X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd7%2Fhook%2Ffield_update.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd7%2Fhook%2Ffield_update.twig;h=79acf7c8dca472c89748aee4eb26efb83b128528;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_update.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_update.twig new file mode 100644 index 000000000..79acf7c8d --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/field_update.twig @@ -0,0 +1,29 @@ +/** + * 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(); + } + } +}