function hook_entity_display_alter

Alters the settings used for displaying an entity.

Parameters

\Drupal\entity\Plugin\Core\Entity\EntityDisplay $display: The entity_display object 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'...

Related topics

1 function implements hook_entity_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_display_alter in drupal/core/modules/node/node.module
Implements hook_entity_display_alter().

File

drupal/core/includes/entity.api.php, line 442
Hooks provided the Entity module.

Code

function hook_entity_display_alter(\Drupal\entity\Plugin\Core\Entity\EntityDisplay $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);
      }
    }
  }
}