function field_purge_field_storage

Same name and namespace in other branches
  1. 11.x core/modules/field/field.purge.inc \field_purge_field_storage()
  2. 10 core/modules/field/field.purge.inc \field_purge_field_storage()
  3. 9 core/modules/field/field.purge.inc \field_purge_field_storage()
  4. 8.9.x 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

Deprecated

in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement.

See also

https://www.drupal.org/node/3494023

File

core/modules/field/field.purge.inc, line 77

Code

function field_purge_field_storage(FieldStorageDefinitionInterface $field_storage) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3494023', E_USER_DEPRECATED);
  /** @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,
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.