Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / entity_display_build_alter.twig
1 /**
2  * Implements hook_entity_display_build_alter().
3  */
4 function {{ machine_name }}_entity_display_build_alter(&$build, $context) {
5   // Append RDF term mappings on displayed taxonomy links.
6   foreach (Element::children($build) as $field_name) {
7     $element = &$build[$field_name];
8     if ($element['#field_type'] == 'entity_reference' && $element['#formatter'] == 'entity_reference_label') {
9       foreach ($element['#items'] as $delta => $item) {
10         $term = $item->entity;
11         if (!empty($term->rdf_mapping['rdftype'])) {
12           $element[$delta]['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];
13         }
14         if (!empty($term->rdf_mapping['name']['predicates'])) {
15           $element[$delta]['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];
16         }
17       }
18     }
19   }
20 }