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

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);
}
doc_Drupal
2016-10-29 09:43:42
Comments
Leave a Comment

Please login to continue.