hook_entity_display_build_alter

hook_entity_display_build_alter(&$build, $context)

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

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 1553
Hooks and documentation related to entities.

Code

function hook_entity_display_build_alter(&$build, $context) {
  // Append RDF term mappings on displayed taxonomy links.
  foreach (Element::children($build) as $field_name) {
    $element = &$build[$field_name];
    if ($element['#field_type'] == 'entity_reference' && $element['#formatter'] == 'entity_reference_label') {
      foreach ($element['#items'] as $delta => $item) {
        $term = $item->entity;
        if (!empty($term->rdf_mapping['rdftype'])) {
          $element[$delta]['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];
        }
        if (!empty($term->rdf_mapping['name']['predicates'])) {
          $element[$delta]['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];
        }
      }
    }
  }
}
doc_Drupal
2016-10-29 09:17:58
Comments
Leave a Comment

Please login to continue.