function FieldStorageDefinitionListener::onFieldStorageDefinitionDelete
Same name in other branches
- 9 core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php \Drupal\Core\Field\FieldStorageDefinitionListener::onFieldStorageDefinitionDelete()
- 10 core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php \Drupal\Core\Field\FieldStorageDefinitionListener::onFieldStorageDefinitionDelete()
- 11.x core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php \Drupal\Core\Field\FieldStorageDefinitionListener::onFieldStorageDefinitionDelete()
Overrides FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionDelete
File
-
core/
lib/ Drupal/ Core/ Field/ FieldStorageDefinitionListener.php, line 116
Class
- FieldStorageDefinitionListener
- Reacts to field storage definition CRUD on behalf of the Entity system.
Namespace
Drupal\Core\FieldCode
public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) {
$entity_type_id = $storage_definition->getTargetEntityTypeId();
// @todo Forward this to all interested handlers, not only storage, once
// iterating handlers is possible: https://www.drupal.org/node/2332857.
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
// Keep the field definition in the deleted fields repository so we can use
// it later during field_purge_batch(), but only if the field has data.
if ($storage_definition instanceof BaseFieldDefinition && $storage instanceof FieldableEntityStorageInterface && $storage->countFieldData($storage_definition, TRUE)) {
$deleted_storage_definition = clone $storage_definition;
$deleted_storage_definition->setDeleted(TRUE);
$this->deletedFieldsRepository
->addFieldDefinition($deleted_storage_definition);
$this->deletedFieldsRepository
->addFieldStorageDefinition($deleted_storage_definition);
}
if ($storage instanceof FieldStorageDefinitionListenerInterface) {
$storage->onFieldStorageDefinitionDelete($storage_definition);
}
$this->entityLastInstalledSchemaRepository
->deleteLastInstalledFieldStorageDefinition($storage_definition);
$this->eventDispatcher
->dispatch(FieldStorageDefinitionEvents::DELETE, new FieldStorageDefinitionEvent($storage_definition));
$this->entityFieldManager
->clearCachedFieldDefinitions();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.