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
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_display_build_alter.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_display_build_alter.twig
new file mode 100644 (file)
index 0000000..330be3d
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * Implements hook_entity_display_build_alter().
+ */
+function {{ machine_name }}_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'];
+        }
+      }
+    }
+  }
+}