function SqlContentEntityStorageSchema::deleteSharedTableSchema

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::deleteSharedTableSchema()
  2. 8.9.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::deleteSharedTableSchema()
  3. 11.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::deleteSharedTableSchema()

Deletes the schema for a field stored in a shared table.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The storage definition of the field being deleted.

1 call to SqlContentEntityStorageSchema::deleteSharedTableSchema()
SqlContentEntityStorageSchema::onFieldStorageDefinitionDelete in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php

File

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

Class

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

Namespace

Drupal\Core\Entity\Sql

Code

protected function deleteSharedTableSchema(FieldStorageDefinitionInterface $storage_definition) {
    // Make sure any entity index involving this field is dropped.
    $this->deleteEntitySchemaIndexes($this->loadEntitySchemaData($this->entityType), $storage_definition);
    $deleted_field_name = $storage_definition->getName();
    $table_mapping = $this->getTableMapping($this->entityType, [
        $storage_definition,
    ]);
    $column_names = $table_mapping->getColumnNames($deleted_field_name);
    $schema_handler = $this->database
        ->schema();
    $shared_table_names = array_diff($table_mapping->getTableNames(), $table_mapping->getDedicatedTableNames());
    // Iterate over the mapped table to find the ones that host the deleted
    // field schema.
    foreach ($shared_table_names as $table_name) {
        foreach ($table_mapping->getFieldNames($table_name) as $field_name) {
            if ($field_name == $deleted_field_name) {
                $schema = $this->getSharedTableFieldSchema($storage_definition, $table_name, $column_names);
                // Drop indexes and unique keys first.
                if (!empty($schema['indexes'])) {
                    foreach ($schema['indexes'] as $name => $specifier) {
                        $schema_handler->dropIndex($table_name, $name);
                    }
                }
                if (!empty($schema['unique keys'])) {
                    foreach ($schema['unique keys'] as $name => $specifier) {
                        $schema_handler->dropUniqueKey($table_name, $name);
                    }
                }
                // Drop columns.
                foreach ($column_names as $column_name) {
                    $schema_handler->dropField($table_name, $column_name);
                }
                // After deleting the field schema skip to the next table.
                break;
            }
        }
    }
    $this->deleteFieldSchemaData($storage_definition);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.