function field_attach_delete

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

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity whose field data to delete.

Related topics

2 calls to field_attach_delete()
FieldAttachOtherTest::testFieldAttachCache in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field cache.
FieldAttachStorageTest::testFieldAttachDelete in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php
Test field_attach_delete().

File

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

Code

function field_attach_delete(EntityInterface $entity) {

  // Ensure we are working with a BC mode entity.
  $entity = $entity
    ->getBCEntity();
  _field_invoke('delete', $entity);

  // Collect the storage backends used by the fields in the entities.
  $storages = array();
  foreach (field_info_instances($entity
    ->entityType(), $entity
    ->bundle()) as $instance) {
    $field = field_info_field_by_id($instance['field_id']);
    $field_id = $field['uuid'];
    $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, $fields);
  }

  // Let other modules act on deleting the entity.
  module_invoke_all('field_attach_delete', $entity);
  $entity_info = $entity
    ->entityInfo();
  if ($entity_info['field_cache']) {
    cache('field')
      ->delete('field:' . $entity
      ->entityType() . ':' . $entity
      ->id());
  }
}