Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_attach_view_alter.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_attach_view_alter.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_attach_view_alter.twig
new file mode 100644 (file)
index 0000000..f060e66
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * Implements hook_field_attach_view_alter().
+ */
+function {{ machine_name }}_field_attach_view_alter(&$output, $context) {
+  // Append RDF term mappings on displayed taxonomy links.
+  foreach (element_children($output) as $field_name) {
+    $element = &$output[$field_name];
+    if ($element['#field_type'] == 'taxonomy_term_reference' && $element['#formatter'] == 'taxonomy_term_reference_link') {
+      foreach ($element['#items'] as $delta => $item) {
+        $term = $item['taxonomy_term'];
+        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'];
+        }
+      }
+    }
+  }
+}