public SqlContentEntityStorageSchema::onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)
Reacts to the deletion of a field storage definition.
Parameters
\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The field being deleted.
Overrides FieldStorageDefinitionListenerInterface::onFieldStorageDefinitionDelete
File
- core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 404
Class
- SqlContentEntityStorageSchema
- Defines a schema handler that supports revisionable, translatable entities.
Namespace
Drupal\Core\Entity\Sql
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition ) { // Only configurable fields currently support purging, so prevent deletion // of ones we can't purge if they have existing data. // @todo Add purging to all fields: https://www.drupal.org/node/2282119. try { if (!( $storage_definition instanceof FieldStorageConfigInterface) && $this ->storage->countFieldData( $storage_definition , TRUE)) { throw new FieldStorageDefinitionUpdateForbiddenException( 'Unable to delete a field (' . $storage_definition ->getName() . ' in ' . $storage_definition ->getTargetEntityTypeId() . ' entity) with data that cannot be purged.' ); } } catch (DatabaseException $e ) { // This may happen when changing field storage schema, since we are not // able to use a table mapping matching the passed storage definition. // @todo Revisit this once we are able to instantiate the table mapping // properly. See https://www.drupal.org/node/2274017. return ; } // Retrieve a table mapping which contains the deleted field still. $table_mapping = $this ->storage->getTableMapping( $this ->entityManager->getLastInstalledFieldStorageDefinitions( $this ->entityType->id()) ); if ( $table_mapping ->requiresDedicatedTableStorage( $storage_definition )) { // Move the table to a unique name while the table contents are being // deleted. $table = $table_mapping ->getDedicatedDataTableName( $storage_definition ); $new_table = $table_mapping ->getDedicatedDataTableName( $storage_definition , TRUE); $this ->database->schema()->renameTable( $table , $new_table ); if ( $this ->entityType->isRevisionable()) { $revision_table = $table_mapping ->getDedicatedRevisionTableName( $storage_definition ); $revision_new_table = $table_mapping ->getDedicatedRevisionTableName( $storage_definition , TRUE); $this ->database->schema()->renameTable( $revision_table , $revision_new_table ); } } // @todo Remove when finalizePurge() is invoked from the outside for all // fields: https://www.drupal.org/node/2282119. if (!( $storage_definition instanceof FieldStorageConfigInterface)) { $this ->performFieldSchemaOperation( 'delete' , $storage_definition ); } } |
Please login to continue.