Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_storage_update_field.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_storage_update_field.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_storage_update_field.twig
new file mode 100644 (file)
index 0000000..97ce774
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * Implements hook_field_storage_update_field().
+ */
+function {{ machine_name }}_field_storage_update_field($field, $prior_field, $has_data) {
+  if (!$has_data) {
+    // There is no data. Re-create the tables completely.
+    $prior_schema = _field_sql_storage_schema($prior_field);
+    foreach ($prior_schema as $name => $table) {
+      db_drop_table($name, $table);
+    }
+    $schema = _field_sql_storage_schema($field);
+    foreach ($schema as $name => $table) {
+      db_create_table($name, $table);
+    }
+  }
+  else {
+    // There is data. See field_sql_storage_field_storage_update_field() for
+    // an example of what to do to modify the schema in place, preserving the
+    // old data as much as possible.
+  }
+  drupal_get_schema(NULL, TRUE);
+}