protected function SqlContentEntityStorageSchema::createEntitySchemaIndexes in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::createEntitySchemaIndexes()
- 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::createEntitySchemaIndexes()
Creates the specified entity schema indexes and keys.
Parameters
array $entity_schema: The entity schema 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::createEntitySchemaIndexes()
- SqlContentEntityStorageSchema::createSharedTableSchema in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorageSchema.php - Creates 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 1917
Class
- SqlContentEntityStorageSchema
- Defines a schema handler that supports revisionable, translatable entities.
Namespace
Drupal\Core\Entity\SqlCode
protected function createEntitySchemaIndexes(array $entity_schema, 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' => 'addIndex',
'unique keys' => 'addUniqueKey',
];
foreach ($this
->getEntitySchemaData($this->entityType, $entity_schema) as $table_name => $schema) {
// Add fields schema because database driver may depend on this data to
// perform index normalization.
$schema['fields'] = $entity_schema[$table_name]['fields'];
foreach ($index_keys as $key => $add_method) {
if (!empty($schema[$key])) {
foreach ($schema[$key] as $name => $specifier) {
// If a set of field columns were specified we process only indexes
// involving them. Only indexes for which all columns exist are
// actually created.
$create = FALSE;
$specifier_columns = array_map(function ($item) {
return is_string($item) ? $item : reset($item);
}, $specifier);
if (!isset($column_names) || array_intersect($specifier_columns, $column_names)) {
$create = TRUE;
foreach ($specifier_columns as $specifier_column_name) {
// This may happen when adding more than one field in the same
// update run. Eventually when all field columns have been
// created the index will be created too.
if (!$schema_handler
->fieldExists($table_name, $specifier_column_name)) {
$create = FALSE;
break;
}
}
}
if ($create) {
$this
->{$add_method}($table_name, $name, $specifier, $schema);
}
}
}
}
}
}