function hook_entity_display_build_alter

Same name 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

File

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

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.