You are here

public function SqlContentEntityStorageSchema::onEntityTypeDelete in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::onEntityTypeDelete()

Reacts to the deletion of the entity type.

Parameters

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

Overrides EntityTypeListenerInterface::onEntityTypeDelete

1 call to SqlContentEntityStorageSchema::onEntityTypeDelete()
SqlContentEntityStorageSchema::onEntityTypeUpdate in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Reacts to the update of the entity type.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 349
Contains \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema.

Class

SqlContentEntityStorageSchema
Defines a schema handler that supports revisionable, translatable entities.

Namespace

Drupal\Core\Entity\Sql

Code

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
  //   https://www.drupal.org/node/2274017.
  $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);
}