annotate 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
rev   line source
Chris@0 1 /**
Chris@0 2 * Implements hook_field_update().
Chris@0 3 */
Chris@0 4 function {{ machine_name }}_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
Chris@0 5 if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node') {
Chris@0 6 $first_call = &drupal_static(__FUNCTION__, array());
Chris@0 7
Chris@0 8 // We don't maintain data for old revisions, so clear all previous values
Chris@0 9 // from the table. Since this hook runs once per field, per object, make
Chris@0 10 // sure we only wipe values once.
Chris@0 11 if (!isset($first_call[$entity->nid])) {
Chris@0 12 $first_call[$entity->nid] = FALSE;
Chris@0 13 db_delete('taxonomy_index')->condition('nid', $entity->nid)->execute();
Chris@0 14 }
Chris@0 15 // Only save data to the table if the node is published.
Chris@0 16 if ($entity->status) {
Chris@0 17 $query = db_insert('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created'));
Chris@0 18 foreach ($items as $item) {
Chris@0 19 $query->values(array(
Chris@0 20 'nid' => $entity->nid,
Chris@0 21 'tid' => $item['tid'],
Chris@0 22 'sticky' => $entity->sticky,
Chris@0 23 'created' => $entity->created,
Chris@0 24 ));
Chris@0 25 }
Chris@0 26 $query->execute();
Chris@0 27 }
Chris@0 28 }
Chris@0 29 }