function hook_ENTITY_TYPE_view_mode_alter
Same name in other branches
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_view_mode_alter()
Change the view mode of a specific entity type currently being displayed.
Parameters
string $view_mode: The view_mode currently displaying the entity.
\Drupal\Core\Entity\EntityInterface $entity: The entity that is being viewed.
Related topics
1 function implements hook_ENTITY_TYPE_view_mode_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- entity_test_entity_test_view_mode_alter in core/
modules/ system/ tests/ modules/ entity_test/ entity_test.module - Implements hook_ENTITY_TYPE_view_mode_alter().
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1707
Code
function hook_ENTITY_TYPE_view_mode_alter(string &$view_mode, \Drupal\Core\Entity\EntityInterface $entity) : void {
// Change the view mode to teaser.
if ($view_mode == 'full') {
$view_mode = 'teaser';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.