Community Documentation

hook_field_insert

7 field.api.php hook_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items)
8 field.api.php hook_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items)

Define custom insert behavior for this module's field types.

Invoked from field_attach_insert().

Parameters

$entity_type: The type of $entity.

$entity: The entity for the operation.

$field: The field structure for the operation.

$instance: The instance structure for $field on $entity's bundle.

$langcode: The language associated with $items.

$items: $entity->{$field['field_name']}[$langcode], or an empty array if unset.

Related topics

File

modules/field/field.api.php, line 462

Code

<?php
function hook_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
  if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node' && $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();
  }
}
?>
Login or register to post comments