function hook_entity_view_display_alter

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_view_display_alter()
  2. 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_view_display_alter()
  3. 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_view_display_alter()

Alter the settings used for displaying an entity.

Parameters

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display that will be used to display the entity components.

array $context: An associative array containing:

  • entity_type: The entity type, e.g., 'node' or 'user'.
  • bundle: The bundle, e.g., 'page' or 'article'.
  • view_mode: The view mode, e.g., 'full', 'teaser', etc.

Related topics

1 function implements hook_entity_view_display_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

node_entity_view_display_alter in core/modules/node/node.module
Implements hook_entity_view_display_alter().

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1768

Code

function hook_entity_view_display_alter(\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, array $context) {
    // Leave field labels out of the search index.
    if ($context['entity_type'] == 'node' && $context['view_mode'] == 'search_index') {
        foreach ($display->getComponents() as $name => $options) {
            if (isset($options['label'])) {
                $options['label'] = 'hidden';
                $display->setComponent($name, $options);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.