2 * Implements hook_field_storage_pre_update().
4 function {{ machine_name }}_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
5 $first_call = &drupal_static(__FUNCTION__, array());
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();
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) {
21 'nid' => $entity->nid,
22 'title' => $entity->title,
23 'tid' => $delta['value'],
24 'sticky' => $entity->sticky,
25 'created' => $entity->created,
27 'last_comment_timestamp' => $entity->created,
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);