2 * Implements hook_field_update().
4 function {{ machine_name }}_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
5 if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node') {
6 $first_call = &drupal_static(__FUNCTION__, array());
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 object, make
10 // sure we only wipe values once.
11 if (!isset($first_call[$entity->nid])) {
12 $first_call[$entity->nid] = FALSE;
13 db_delete('taxonomy_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('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created'));
18 foreach ($items as $item) {
20 'nid' => $entity->nid,
21 'tid' => $item['tid'],
22 'sticky' => $entity->sticky,
23 'created' => $entity->created,