function hook_entity_display_build_alter in Drupal 8
Same name and namespace in other branches
- 9 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().
1 invocation of hook_entity_display_build_alter()
- KernelTestBaseTest::testEnableModulesLoad in core/
modules/ simpletest/ src/ Tests/ KernelTestBaseTest.php - Tests expected load behavior of enableModules().
File
- core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1753 - 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'];
}
}
}
}
}