Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_insert.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_insert.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_insert.twig
new file mode 100644 (file)
index 0000000..a164ab4
--- /dev/null
@@ -0,0 +1,17 @@
+/**
+ * Implements hook_field_insert().
+ */
+function {{ machine_name }}_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
+  if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node' && $entity->status) {
+    $query = db_insert('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created', ));
+    foreach ($items as $item) {
+      $query->values(array(
+        'nid' => $entity->nid,
+        'tid' => $item['tid'],
+        'sticky' => $entity->sticky,
+        'created' => $entity->created,
+      ));
+    }
+    $query->execute();
+  }
+}