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: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_test_entity_display_build_alter in core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_display_build_alter().
field_test_entity_display_build_alter in core/modules/field/tests/modules/field_test/field_test.module
Implements hook_entity_display_build_alter().

File

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

Code

function hook_entity_display_build_alter(&$build, $context) {
    
    /** @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.