Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / field_storage_pre_update.twig
1 /**
2  * Implements hook_field_storage_pre_update().
3  */
4 function {{ machine_name }}_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
5   $first_call = &drupal_static(__FUNCTION__, array());
6
7   if ($entity_type == 'node' && $entity->status && _forum_node_check_node_type($entity)) {
8     // We don't maintain data for old revisions, so clear all previous values
9     // from the table. Since this hook runs once per field, per entity, make
10     // sure we only wipe values once.
11     if (!isset($first_call[$entity->nid])) {
12       $first_call[$entity->nid] = FALSE;
13       db_delete('forum_index')->condition('nid', $entity->nid)->execute();
14     }
15     // Only save data to the table if the node is published.
16     if ($entity->status) {
17       $query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
18       foreach ($entity->taxonomy_forums as $language) {
19         foreach ($language as $delta) {
20           $query->values(array(
21             'nid' => $entity->nid,
22             'title' => $entity->title,
23             'tid' => $delta['value'],
24             'sticky' => $entity->sticky,
25             'created' => $entity->created,
26             'comment_count' => 0,
27             'last_comment_timestamp' => $entity->created,
28           ));
29         }
30       }
31       $query->execute();
32       // The logic for determining last_comment_count is fairly complex, so
33       // call _forum_update_forum_index() too.
34       _forum_update_forum_index($entity->nid);
35     }
36   }
37 }