public function SqlContentEntityStorageSchema::onEntityTypeUpdate in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::onEntityTypeUpdate()
- 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::onEntityTypeUpdate()
Reacts to the update of the entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The updated entity type definition.
\Drupal\Core\Entity\EntityTypeInterface $original: The original entity type definition.
Overrides EntityTypeListenerInterface::onEntityTypeUpdate
File
- core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorageSchema.php, line 356
Class
- SqlContentEntityStorageSchema
- Defines a schema handler that supports revisionable, translatable entities.
Namespace
Drupal\Core\Entity\SqlCode
public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
$this
->checkEntityType($entity_type);
$this
->checkEntityType($original);
// If no schema changes are needed, we don't need to do anything.
if (!$this
->requiresEntityStorageSchemaChanges($entity_type, $original)) {
return;
}
// If shared table schema changes are needed, we can't proceed.
if (!class_exists($original
->getStorageClass()) || $this
->hasSharedTableStructureChange($entity_type, $original)) {
throw new EntityStorageException('It is not possible to change the entity type schema outside of a batch context. Use EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead.');
}
// Drop original indexes and unique keys.
$this
->deleteEntitySchemaIndexes($this
->loadEntitySchemaData($entity_type));
// Create new indexes and unique keys.
$entity_schema = $this
->getEntitySchema($entity_type, TRUE);
$this
->createEntitySchemaIndexes($entity_schema);
// Store the updated entity schema.
$this
->saveEntitySchemaData($entity_type, $entity_schema);
}