You are here

function field_purge_field_storage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/field.purge.inc \field_purge_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

1 call to field_purge_field_storage()
field_purge_batch in core/modules/field/field.purge.inc
Purges a batch of deleted Field API data, field storages, or fields.

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,
  ));
}