function hook_entity_display_build_alter

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

Alter the render array generated by an EntityDisplay for an entity.

Parameters

array $build: The renderable array generated by the EntityDisplay.

array $context: An associative array containing:

  • entity: The entity being rendered.
  • view_mode: The view mode; for example, 'full' or 'teaser'.
  • display: The EntityDisplay holding the display options.

Related topics

2 functions implement hook_entity_display_build_alter()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

EntityTestHooks::entityDisplayBuildAlter in core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php
Implements hook_entity_display_build_alter().
FieldTestHooks::entityDisplayBuildAlter in core/modules/field/tests/modules/field_test/src/Hook/FieldTestHooks.php
Implements hook_entity_display_build_alter().

File

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

Code

function hook_entity_display_build_alter(&$build, $context) : void {
  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $context['entity'];
  if ($entity->getEntityTypeId() === 'my_entity' && $entity->bundle() === 'display_build_alter_bundle') {
    $build['entity_display_build_alter']['#markup'] = 'Content added in hook_entity_display_build_alter for entity id ' . $entity->id();
  }
}

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