Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Matroskeen on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.0.x
Introduced in version:
10.0.0
Description:
Before, the implementations of hook_entity_view_mode_alter()
hook received $context
array as 3rd argument, that was supposed to provide some additional context information. In practice, the $context
was always empty since #2073217: Remove the $langcode parameter from the entity view/render system was committed.
It was decided to remove it as it's not necessary.
Before:
function hook_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\EntityInterface $entity, $context) {
if ($entity->getEntityTypeId() == 'node' && $view_mode == 'teaser') {
$view_mode = 'my_custom_view_mode';
}
}
After:
function hook_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'node' && $view_mode == 'teaser') {
$view_mode = 'my_custom_view_mode';
}
}
Impacts:
Module developers