hook_entity_view_display_alter

hook_entity_view_display_alter(\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, array $context)

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

Entity CRUD, editing, and view hooks
Hooks used in various entity operations.
Hooks
Define functions that alter the behavior of Drupal core.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1528
Hooks and documentation related to entities.

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);
      }
    }
  }
}
doc_Drupal
2016-10-29 09:18:08
Comments
Leave a Comment

Please login to continue.