You are here

function field_purge_field_storage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field/field.purge.inc \field_purge_field_storage()
  2. 10 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\Core\Field\FieldStorageDefinitionInterface $field_storage: The field storage to purge.

Throws

\Drupal\Core\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 154
Provides support for field data purge after mass deletion.

Code

function field_purge_field_storage(FieldStorageDefinitionInterface $field_storage) {

  /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
  $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
  $fields = $deleted_fields_repository
    ->getFieldDefinitions($field_storage
    ->getUniqueStorageIdentifier());
  if (count($fields) > 0) {
    throw new FieldException("Attempt to purge a field storage '{$field_storage->getName()}' that still has fields.");
  }
  $deleted_fields_repository
    ->removeFieldStorageDefinition($field_storage);

  // Notify the storage layer.
  \Drupal::entityTypeManager()
    ->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', [
    $field_storage,
  ]);
}