Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_storage_pre_insert.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_storage_pre_insert.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_storage_pre_insert.twig
new file mode 100644 (file)
index 0000000..aa100df
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * Implements hook_field_storage_pre_insert().
+ */
+function {{ machine_name }}_field_storage_pre_insert($entity_type, $entity, &$skip_fields) {
+  if ($entity_type == 'node' && $entity->status && _forum_node_check_node_type($entity)) {
+    $query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
+    foreach ($entity->taxonomy_forums as $language) {
+      foreach ($language as $delta) {
+        $query->values(array(
+          'nid' => $entity->nid,
+          'title' => $entity->title,
+          'tid' => $delta['value'],
+          'sticky' => $entity->sticky,
+          'created' => $entity->created,
+          'comment_count' => 0,
+          'last_comment_timestamp' => $entity->created,
+        ));
+      }
+    }
+    $query->execute();
+  }
+}