Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_prepare_view.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_prepare_view.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_prepare_view.twig
new file mode 100644 (file)
index 0000000..bb44e13
--- /dev/null
@@ -0,0 +1,18 @@
+/**
+ * Implements hook_field_prepare_view().
+ */
+function {{ machine_name }}_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
+  // Sample code from image.module: if there are no images specified at all,
+  // use the default image.
+  foreach ($entities as $id => $entity) {
+    if (empty($items[$id]) && $field['settings']['default_image']) {
+      if ($file = file_load($field['settings']['default_image'])) {
+        $items[$id][0] = (array) $file + array(
+          'is_default' => TRUE,
+          'alt' => '',
+          'title' => '',
+        );
+      }
+    }
+  }
+}