Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_attach_submit.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_attach_submit.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_attach_submit.twig
new file mode 100644 (file)
index 0000000..737e235
--- /dev/null
@@ -0,0 +1,11 @@
+/**
+ * Implements hook_field_attach_submit().
+ */
+function {{ machine_name }}_field_attach_submit($entity_type, $entity, $form, &$form_state) {
+  // Sample case of an 'Empty the field' checkbox added on the form, allowing
+  // a given field to be emptied.
+  $values = drupal_array_get_nested_value($form_state['values'], $form['#parents']);
+  if (!empty($values['empty_field_foo'])) {
+    unset($entity->field_foo);
+  }
+}