That's a task for hook_entity_view_mode_alter()
.
Change the view mode of an entity that is being displayed.
See the following working sample that automatically lets the node whose ID is 123 be rendered in the teaser view mode when accessed as full page. You could simply add your own logic (type, user, datetime etc.) as well.
/**
* Implements hook_entity_view_mode_alter().
*/
function MYMODULE_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\EntityInterface $entity, $context) {
// Change the view mode to teaser on full page view for node ID 123.
if ($entity->getEntityTypeId() == 'node' && $entity->id() == '123' && $view_mode == 'full') {
$view_mode = 'teaser';
}
}
As you can maybe imagine, from $entity
you can get any field value of a node. You could also add some select list field or taxonomy reference to your content type and then adjust that value node-wise. Finally you can use above code snippet to switch the view mode depending on these values. Mission accomplished.
hook_entity_view_mode_alter
to very easily build that yourself. Added answer below.