function hook_field_delete

Define custom delete behavior for this module's field data.

This hook is invoked from field_attach_delete() on the module that defines a field, during the process of deleting an entity object (node, taxonomy term, etc.). It is invoked just before the data for this field on the particular entity object is deleted from field storage. Only field modules that are storing or tracking information outside the standard field storage mechanism need to implement this hook.

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.

See also

hook_field_insert()

hook_field_update()

Related topics

3 functions implement hook_field_delete()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_test_field_delete in drupal/core/modules/field/tests/modules/field_test/field_test.field.inc
Implements hook_field_delete().
file_field_delete in drupal/core/modules/file/file.field.inc
Implements hook_field_delete().
image_field_delete in drupal/core/modules/image/image.field.inc
Implements hook_field_delete().
2 invocations of hook_field_delete()
field_attach_delete in drupal/core/modules/field/field.attach.inc
Deletes field data for an existing entity. This deletes all revisions of field data for the entity.
field_purge_data in drupal/core/modules/field/field.crud.inc
Purges the field data for a single field on a single pseudo-entity.

File

drupal/core/modules/field/field.api.php, line 587

Code

function hook_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
  foreach ($items as $delta => $item) {

    // For hook_file_references(), remember that this is being deleted.
    $item['file_field_name'] = $field['field_name'];

    // Pass in the ID of the object that is being removed so all references can
    // be counted in hook_file_references().
    $item['file_field_type'] = $entity_type;
    $item['file_field_id'] = $entity
      ->id();
    file_field_delete_file($item, $field, $entity_type, $entity
      ->id());
  }
}