Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_delete.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_delete.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_delete.twig
new file mode 100644 (file)
index 0000000..807301a
--- /dev/null
@@ -0,0 +1,15 @@
+/**
+ * Implements hook_field_delete().
+ */
+function {{ machine_name }}_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
+  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
+  foreach ($items as $delta => $item) {
+    // For hook_file_references(), remember that this is being deleted.
+    $item['file_field_name'] = $field['field_name'];
+    // Pass in the ID of the object that is being removed so all references can
+    // be counted in hook_file_references().
+    $item['file_field_type'] = $entity_type;
+    $item['file_field_id'] = $id;
+    file_field_delete_file($item, $field, $entity_type, $id);
+  }
+}