function SqlContentEntityStorageSchema::getEntitySchema
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getEntitySchema()
- 8.9.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getEntitySchema()
- 11.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getEntitySchema()
Gets the entity schema for the specified entity type.
Entity types may override this method in order to optimize the generated schema of the entity tables. However, only cross-field optimizations should be added here; e.g., an index spanning multiple fields. Optimizations that apply to a single field have to be added via SqlContentEntityStorageSchema::getSharedTableFieldSchema() instead.
Parameters
\Drupal\Core\Entity\ContentEntityTypeInterface $entity_type: The entity type definition.
bool $reset: (optional) If set to TRUE static cache will be ignored and a new schema array generation will be performed. Defaults to FALSE.
Return value
array A Schema API array describing the entity schema, excluding dedicated field tables.
12 calls to SqlContentEntityStorageSchema::getEntitySchema()
- CommentStorageSchema::getEntitySchema in core/
modules/ comment/ src/ CommentStorageSchema.php - Gets the entity schema for the specified entity type.
- ContentModerationStateStorageSchema::getEntitySchema in core/
modules/ content_moderation/ src/ ContentModerationStateStorageSchema.php - Gets the entity schema for the specified entity type.
- EntityTestUpdateStorageSchema::getEntitySchema in core/
modules/ system/ tests/ modules/ entity_test_update/ src/ EntityTestUpdateStorageSchema.php - Gets the entity schema for the specified entity type.
- NodeStorageSchema::getEntitySchema in core/
modules/ node/ src/ NodeStorageSchema.php - Gets the entity schema for the specified entity type.
- PathAliasStorageSchema::getEntitySchema in core/
modules/ path_alias/ src/ PathAliasStorageSchema.php - Gets the entity schema for the specified entity type.
7 methods override SqlContentEntityStorageSchema::getEntitySchema()
- CommentStorageSchema::getEntitySchema in core/
modules/ comment/ src/ CommentStorageSchema.php - Gets the entity schema for the specified entity type.
- ContentModerationStateStorageSchema::getEntitySchema in core/
modules/ content_moderation/ src/ ContentModerationStateStorageSchema.php - Gets the entity schema for the specified entity type.
- EntityTestUpdateStorageSchema::getEntitySchema in core/
modules/ system/ tests/ modules/ entity_test_update/ src/ EntityTestUpdateStorageSchema.php - Gets the entity schema for the specified entity type.
- NodeStorageSchema::getEntitySchema in core/
modules/ node/ src/ NodeStorageSchema.php - Gets the entity schema for the specified entity type.
- PathAliasStorageSchema::getEntitySchema in core/
modules/ path_alias/ src/ PathAliasStorageSchema.php - Gets the entity schema for the specified entity type.
File
-
core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorageSchema.php, line 941
Class
- SqlContentEntityStorageSchema
- Defines a schema handler that supports revisionable, translatable entities.
Namespace
Drupal\Core\Entity\SqlCode
protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
$this->checkEntityType($entity_type);
$entity_type_id = $entity_type->id();
if (!isset($this->schema[$entity_type_id]) || $reset) {
// Prepare basic information about the entity type.
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = $this->getTableMapping($entity_type, $this->fieldStorageDefinitions);
$tables = $this->getEntitySchemaTables($table_mapping);
// Initialize the table schema.
$schema[$tables['base_table']] = $this->initializeBaseTable($entity_type);
if (isset($tables['revision_table'])) {
$schema[$tables['revision_table']] = $this->initializeRevisionTable($entity_type);
}
if (isset($tables['data_table'])) {
$schema[$tables['data_table']] = $this->initializeDataTable($entity_type);
}
if (isset($tables['revision_data_table'])) {
$schema[$tables['revision_data_table']] = $this->initializeRevisionDataTable($entity_type);
}
// We need to act only on shared entity schema tables.
$table_names = array_diff($table_mapping->getTableNames(), $table_mapping->getDedicatedTableNames());
foreach ($table_names as $table_name) {
if (!isset($schema[$table_name])) {
$schema[$table_name] = [];
}
foreach ($table_mapping->getFieldNames($table_name) as $field_name) {
if (!isset($this->fieldStorageDefinitions[$field_name])) {
throw new FieldException("Field storage definition for '{$field_name}' could not be found.");
}
elseif ($table_mapping->allowsSharedTableStorage($this->fieldStorageDefinitions[$field_name])) {
$column_names = $table_mapping->getColumnNames($field_name);
$storage_definition = $this->fieldStorageDefinitions[$field_name];
$schema[$table_name] = array_merge_recursive($schema[$table_name], $this->getSharedTableFieldSchema($storage_definition, $table_name, $column_names));
}
}
}
// Process tables after having gathered field information.
if (isset($tables['data_table'])) {
$this->processDataTable($entity_type, $schema[$tables['data_table']]);
}
if (isset($tables['revision_data_table'])) {
$this->processRevisionDataTable($entity_type, $schema[$tables['revision_data_table']]);
}
// Add an index for the 'published' entity key.
if (is_subclass_of($entity_type->getClass(), EntityPublishedInterface::class)) {
$published_key = $entity_type->getKey('published');
if ($published_key && isset($this->fieldStorageDefinitions[$published_key]) && !$this->fieldStorageDefinitions[$published_key]
->hasCustomStorage()) {
$published_field_table = $table_mapping->getFieldTableName($published_key);
$id_key = $entity_type->getKey('id');
if ($bundle_key = $entity_type->getKey('bundle')) {
$key = "{$published_key}_{$bundle_key}";
$columns = [
$published_key,
$bundle_key,
$id_key,
];
}
else {
$key = $published_key;
$columns = [
$published_key,
$id_key,
];
}
$schema[$published_field_table]['indexes'][$this->getEntityIndexName($entity_type, $key)] = $columns;
}
}
$this->schema[$entity_type_id] = $schema;
}
return $this->schema[$entity_type_id];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.