By arisen on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.3.x
Introduced in version:
10.3.0
Issue links:
Description:
New hook hook_ENTITY_TYPE_view_mode_alter() has been added to allow modules implement view mode alter hook for only specific entity types.
For Usage, the module developers have to replace ENTITY_TYPE with node, user etc. Examples below:
Before
function example_entity_view_mode_alter(&$view_mode, \Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'node' && $view_mode == 'full') {
$view_mode = 'custom';
}
}After
function example_node_view_mode_alter(&$view_mode, \Drupal\Core\Entity\EntityInterface $entity) {
if ($view_mode == 'full') {
$view_mode = 'custom';
}
}Impacts:
Module developers
Themers
Site templates, recipes and distribution developers