Mercurial > hg > cmmr2012-drupal-site
view vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_update.twig @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
line wrap: on
line source
/** * Implements hook_field_update(). */ function {{ machine_name }}_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node') { $first_call = &drupal_static(__FUNCTION__, array()); // We don't maintain data for old revisions, so clear all previous values // from the table. Since this hook runs once per field, per object, make // sure we only wipe values once. if (!isset($first_call[$entity->nid])) { $first_call[$entity->nid] = FALSE; db_delete('taxonomy_index')->condition('nid', $entity->nid)->execute(); } // Only save data to the table if the node is published. if ($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(); } } }