SqlContentEntityStorageSchema::onEntityTypeDelete

public SqlContentEntityStorageSchema::onEntityTypeDelete(EntityTypeInterface $entity_type)

Reacts to the deletion of the entity type.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type being deleted.

Overrides EntityTypeListenerInterface::onEntityTypeDelete

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 344

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
public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
  $this->checkEntityType($entity_type);
  $schema_handler = $this->database->schema();
  $actual_definition = $this->entityManager->getDefinition($entity_type->id());
  // @todo Instead of switching the wrapped entity type, we should be able to
  //   instantiate a new table mapping for each entity type definition. See
  $this->storage->setEntityType($entity_type);
 
  // Delete entity tables.
  foreach ($this->getEntitySchemaTables() as $table_name) {
    if ($schema_handler->tableExists($table_name)) {
      $schema_handler->dropTable($table_name);
    }
  }
 
  // Delete dedicated field tables.
  $field_storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type->id());
  $this->originalDefinitions = $field_storage_definitions;
  $table_mapping = $this->storage->getTableMapping($field_storage_definitions);
  foreach ($field_storage_definitions as $field_storage_definition) {
    // If we have a field having dedicated storage we need to drop it,
    // otherwise we just remove the related schema data.
    if ($table_mapping->requiresDedicatedTableStorage($field_storage_definition)) {
      $this->deleteDedicatedTableSchema($field_storage_definition);
    }
    elseif ($table_mapping->allowsSharedTableStorage($field_storage_definition)) {
      $this->deleteFieldSchemaData($field_storage_definition);
    }
  }
  $this->originalDefinitions = NULL;
 
  $this->storage->setEntityType($actual_definition);
 
  // Delete the entity schema.
  $this->deleteEntitySchemaData($entity_type);
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.