field_purge_field_storage

field_purge_field_storage(FieldStorageConfigInterface $field_storage)

Purges a field record from the database.

This function assumes all fields for the field storage has already been purged, and should only be called by field_purge_batch().

Parameters

\Drupal\field\FieldStorageConfigInterface $field_storage: The field storage to purge.

Throws

Drupal\field\FieldException

Related topics

Field API bulk data deletion
Cleans up after Field API bulk deletion operations.

File

core/modules/field/field.purge.inc, line 161
Provides support for field data purge after mass deletion.

Code

function field_purge_field_storage(FieldStorageConfigInterface $field_storage) {
  $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
  if (count($fields) > 0) {
    throw new FieldException(t('Attempt to purge a field storage @field_name that still has fields.', array('@field_name' => $field_storage->getName())));
  }

  $state = \Drupal::state();
  $deleted_storages = $state->get('field.storage.deleted');
  unset($deleted_storages[$field_storage->uuid()]);
  $state->set('field.storage.deleted', $deleted_storages);

  // Notify the storage layer.
  \Drupal::entityManager()->getStorage($field_storage->getTargetEntityTypeId())->finalizePurge($field_storage);

  // Invoke external hooks after the cache is cleared for API consistency.
  \Drupal::moduleHandler()->invokeAll('field_purge_field_storage', array($field_storage));
}
doc_Drupal
2016-10-29 09:13:00
Comments
Leave a Comment

Please login to continue.