You are here

function field_attach_delete in Drupal 7

Delete field data for an existing entity. This deletes all revisions of field data for the entity.

Parameters

$entity_type: The type of $entity; e.g. 'node' or 'user'.

$entity: The entity whose field data to delete.

Related topics

6 calls to field_attach_delete()
comment_delete_multiple in modules/comment/comment.module
Delete comments and all their replies.
FieldAttachOtherTestCase::testFieldAttachCache in modules/field/tests/field.test
Test field cache.
FieldAttachStorageTestCase::testFieldAttachDelete in modules/field/tests/field.test
Test field_attach_delete().
node_delete_multiple in modules/node/node.module
Deletes multiple nodes.
taxonomy_term_delete in modules/taxonomy/taxonomy.module
Delete a term.

... See full list

File

modules/field/field.attach.inc, line 1045
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.

Code

function field_attach_delete($entity_type, $entity) {
  _field_invoke('delete', $entity_type, $entity);
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

  // Collect the storage backends used by the fields in the entities.
  $storages = array();
  foreach (field_info_instances($entity_type, $bundle) as $instance) {
    $field = field_info_field_by_id($instance['field_id']);
    $field_id = $field['id'];
    $storages[$field['storage']['type']][$field_id] = $field_id;
  }

  // Field storage backends delete their data.
  foreach ($storages as $storage => $fields) {
    $storage_info = field_info_storage_types($storage);
    module_invoke($storage_info['module'], 'field_storage_delete', $entity_type, $entity, $fields);
  }

  // Let other modules act on deleting the entity.
  module_invoke_all('field_attach_delete', $entity_type, $entity);
  $entity_info = entity_get_info($entity_type);
  if ($entity_info['field cache']) {
    cache_clear_all("field:{$entity_type}:{$id}", 'cache_field');
  }
}