function SqlContentEntityStorageSchema::deleteEntitySchemaIndexes

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

Deletes the specified entity schema indexes and keys.

Parameters

array $entity_schema_data: The entity schema data definition.

\Drupal\Core\Field\FieldStorageDefinitionInterface|null $storage_definition: (optional) If a field storage definition is specified, only indexes and keys involving its columns will be processed. Otherwise all defined entity indexes and keys will be processed.

2 calls to SqlContentEntityStorageSchema::deleteEntitySchemaIndexes()
SqlContentEntityStorageSchema::deleteSharedTableSchema in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Deletes the schema for a field stored in a shared table.
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 1983

Class

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

Namespace

Drupal\Core\Entity\Sql

Code

protected function deleteEntitySchemaIndexes(array $entity_schema_data, FieldStorageDefinitionInterface $storage_definition = NULL) {
    $schema_handler = $this->database
        ->schema();
    if ($storage_definition) {
        $table_mapping = $this->getTableMapping($this->entityType, [
            $storage_definition,
        ]);
        $column_names = $table_mapping->getColumnNames($storage_definition->getName());
    }
    $index_keys = [
        'indexes' => 'dropIndex',
        'unique keys' => 'dropUniqueKey',
    ];
    foreach ($entity_schema_data as $table_name => $schema) {
        foreach ($index_keys as $key => $drop_method) {
            if (!empty($schema[$key])) {
                foreach ($schema[$key] as $name => $specifier) {
                    $specifier_columns = array_map(function ($item) {
                        return is_string($item) ? $item : reset($item);
                    }, $specifier);
                    if (!isset($column_names) || array_intersect($specifier_columns, $column_names)) {
                        $schema_handler->{$drop_method}($table_name, $name);
                    }
                }
            }
        }
    }
}

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