diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index a10b2d1..1f37641 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -11,6 +11,8 @@ use Drupal\Core\Database\Database; use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Entity\Schema\ContentEntitySchemaHandler; +use Drupal\Core\Entity\Schema\ContentEntitySchemaHandlerInterface; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\field\FieldInfo; use Drupal\field\FieldConfigUpdateForbiddenException; @@ -27,7 +29,59 @@ * This class can be used as-is by most simple entity types. Entity types * requiring special handling can extend the class. */ -class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements SqlStorageInterface { +class ContentEntityDatabaseStorage extends ContentEntityStorageBase + implements FieldableEntityStorageInterface, ContentEntitySchemaHandlerInterface, SqlStorageInterface { + + /** + * The base table layout: no revision or multilingual support for base fields. + * + * @var int + */ + const LAYOUT_BASE = 0; + + /** + * The revision table layout: provides revision support for base fields. + * + * @var int + */ + const LAYOUT_REVISION = 1; + + /** + * The multilingual table layout: provides multilingual support for base + * fields. + * + * @var int + */ + const LAYOUT_MULTILINGUAL = 2; + + /** + * The multilingual revision table layout: provides revision and multilingual + * support for base fields. + * + * @var int + */ + const LAYOUT_MULTILINGUAL_REVISION = 3; + + /** + * The base field definitions for this entity type. + * + * @var \Drupal\Core\Field\FieldDefinitionInterface[] + */ + protected $fieldDefinitions; + + /** + * The table layout associated to the entity type. + * + * @var int + */ + protected $layoutType; + + /** + * A mapping of schema fields that will be stored per entity table. + * + * @var array + */ + protected $tableMapping; /** * Name of entity's revision database table field, if it supports revisions. @@ -131,6 +185,7 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa $this->database = $database; $this->fieldInfo = $field_info; $this->entityManager = $entity_manager; + $this->fieldDefinitions = $entity_manager->getBaseFieldDefinitions($entity_type->id()); // Check if the entity type supports IDs. if ($this->entityType->hasKey('id')) { @@ -165,6 +220,173 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa /** * {@inheritdoc} */ + public function getSchema() { + return $this->schemaBuilder()->getSchema(); + } + + /** + * Gets the schema builder for this storage controller. + */ + protected function schemaBuilder() { + if (!isset($this->schemaBuilder)) { + $this->schemaBuilder = new ContentEntitySchemaHandler($this->entityManager, $this->entityType, $this); + } + return $this->schemaBuilder; + } + + /** + * {@inheritdoc} + */ + public function getTableMapping() { + if (!isset($this->tableMapping)) { + $table_mapping = array(); + + // @todo Remove this. This is currently needed because some entity types + // declare a schema that does not match their field definitions. + // Therefore we use the legacy schema if it's still declared. This + // allows to iteratively enable the automatic schema generation for all + // entity types. + if (drupal_get_schema($this->baseTable)) { + $tables = array_filter(array($this->baseTable, $this->revisionTable, $this->dataTable, $this->revisionDataTable)); + foreach ($tables as $table) { + foreach (array_keys(drupal_get_schema($table)['fields']) as $field_name) { + $table_mapping[$table][$field_name] = array($field_name); + } + } + } + else { + $entity_keys = array_filter(array( + 'id' => $this->entityType->getKey('id'), + 'revision' => $this->entityType->getKey('revision'), + 'bundle' => $this->entityType->getKey('bundle'), + 'uuid' => $this->entityType->getKey('uuid'), + )); + // @todo This will become unnecessary once https://drupal.org/node/2143729 + // has landed. + if ($this->entityType->getDataTable()) { + $entity_keys['langcode'] = 'langcode'; + $entity_keys['default_langcode'] = 'default_langcode'; + }; + + $key_fields = $entity_keys; + unset($key_fields['default_langcode']); + $key_fields = array_values($key_fields); + + $storable_definitions = array_filter($this->fieldDefinitions, function (FieldDefinitionInterface $field_definition) { + return !$field_definition->isComputed() && !$field_definition->hasCustomStorage(); + }); + $storable_fields = array_keys($storable_definitions); + + // @todo Provide automatic definitions for revision metadata fields. + // Rename 'log' to 'revision_log'. + $revision_metadata_fields = array('revision_timestamp', 'revision_uid', 'log'); + $revisionable_filter_callback = function (FieldDefinitionInterface $definition) { return $definition->isRevisionable(); }; + + $this->getLayoutType(); + switch (TRUE) { + // The base layout stores all the base field values in the base table. + case $this->layoutType == static::LAYOUT_BASE: + $table_mapping[$this->baseTable] = $this->processFields(array_merge($key_fields, array_diff($storable_fields, $key_fields))); + break; + + // The base layout stores all the base field values in the base table. + // Revisionable fields are also stored in the revision table. + case $this->layoutType == static::LAYOUT_REVISION: + $table_mapping[$this->baseTable] = $this->processFields(array_merge($key_fields, array_diff($storable_fields, $key_fields, $revision_metadata_fields))); + $revision_key_fields = array($entity_keys['id'], $entity_keys['revision']); + $revisionable_fields = array_keys(array_filter($storable_definitions, $revisionable_filter_callback)); + $table_mapping[$this->revisionTable] = $this->processFields(array_merge($revision_key_fields, $revisionable_fields)); + break; + + // Multilingual layouts store key field values in the base table. The + // other base field values are stored in the data table, no matter + // whether they are translatable or not. The data table holds also a + // denormalized copy of the bundle field value to allow for more + // performant queries. + case $this->layoutType == static::LAYOUT_MULTILINGUAL: + $table_mapping[$this->baseTable] = $this->processFields($key_fields); + $data_key_fields = array_diff($key_fields, array('uuid')); + $data_fields = array_diff($storable_fields, $key_fields); + $table_mapping[$this->dataTable] = $this->processFields(array_merge($data_key_fields, $data_fields)); + break; + + // The revisionable multilingual layout stores key field values in the + // base table, except for language, which is stored in the revision + // table along with revision metadata. The revision data table holds + // data field values for all the available revisions without + // denormalizations. + case $this->layoutType == static::LAYOUT_MULTILINGUAL_REVISION: + $table_mapping[$this->baseTable] = $this->processFields(array_diff($key_fields, array($entity_keys['langcode']))); + $data_key_fields = array_diff($key_fields, array('uuid')); + $data_fields = array_diff($storable_fields, $key_fields, $revision_metadata_fields); + $table_mapping[$this->dataTable] = $this->processFields(array_merge($data_key_fields, $data_fields)); + $table_mapping[$this->revisionTable] = $this->processFields(array_merge(array($entity_keys['id'], $entity_keys['revision'], $entity_keys['langcode']), $revision_metadata_fields)); + $revision_data_key_fields = array_diff($key_fields, array($entity_keys['bundle'], $entity_keys['uuid'])); + $revisionable_fields = array_keys(array_filter($storable_definitions, $revisionable_filter_callback)); + $revision_data_fields = array_diff($revisionable_fields, $revision_metadata_fields, $revision_data_key_fields); + $table_mapping[$this->revisionDataTable] = $this->processFields(array_merge($revision_data_key_fields, $revision_data_fields)); + break; + } + } + + $this->tableMapping = $table_mapping; + } + + return $this->tableMapping; + } + + /** + * Returns the current layout type. + * + * @return int + * An integer value identifiying the current layour type. + * + * @see static::LAYOUT_BASE + * @see static::LAYOUT_REVISION + * @see static::LAYOUT_MULTILINGUAL + * @see static::LAYOUT_MULTILINGUAL_REVISION + */ + protected function getLayoutType() { + if (!isset($this->layoutType)) { + $this->layoutType = static::LAYOUT_BASE; + if ($this->entityType->hasKey('revision')) { + $this->layoutType |= static::LAYOUT_REVISION; + } + if ($this->entityType->isTranslatable()) { + $this->layoutType |= static::LAYOUT_MULTILINGUAL; + } + } + return $this->layoutType; + } + + /** + * Returns a mapping between field and column names. + * + * @param array $field_names + * An array of names of fields to map. + * + * @return array + * An associative array of arrays of column names keyed by field name. + */ + protected function processFields($field_names) { + $mapping = array(); + foreach ($field_names as $field_name) { + $columns = isset($this->fieldDefinitions[$field_name]) ? array_keys($this->fieldDefinitions[$field_name]->getColumns()) : array(); + if (count($columns) > 1) { + foreach ($columns as $column) { + $mapping[$field_name][] = $field_name . '__' . $column; + } + } + else { + $mapping[$field_name] = array($field_name); + } + } + return $mapping; + } + + /** + * {@inheritdoc} + */ public function loadMultiple(array $ids = NULL) { $entities = array(); @@ -302,10 +524,10 @@ protected function attachPropertyData(array &$entities) { $table_mapping = $this->getTableMapping(); $translations = array(); if ($this->revisionDataTable) { - $data_column_names = call_user_func_array('array_merge', array_diff_key($table_mapping['revision_data_table'], $table_mapping['base_table'])); + $data_column_names = call_user_func_array('array_merge', array_diff_key($table_mapping[$this->revisionDataTable], $table_mapping[$this->baseTable])); } else { - $data_column_names = call_user_func_array('array_merge', $table_mapping['data_table']); + $data_column_names = call_user_func_array('array_merge', $table_mapping[$this->dataTable]); } $data_column_names = array_combine($data_column_names, $data_column_names); @@ -439,11 +661,11 @@ protected function buildQuery($ids, $revision_id = FALSE) { // Add fields from the {entity} table. $table_mapping = $this->getTableMapping(); - $entity_fields = call_user_func_array('array_merge', $table_mapping['base_table']); + $entity_fields = call_user_func_array('array_merge', $table_mapping[$this->baseTable]); if ($this->revisionTable) { // Add all fields from the {entity_revision} table. - $entity_revision_fields = call_user_func_array('array_merge', $table_mapping['revision_table']); + $entity_revision_fields = call_user_func_array('array_merge', $table_mapping[$this->revisionTable]); $entity_revision_fields = array_combine($entity_revision_fields, $entity_revision_fields); // The ID field is provided by entity, so remove it. unset($entity_revision_fields[$this->idKey]); @@ -1541,28 +1763,4 @@ static public function _fieldColumnName(FieldConfigInterface $field, $column) { return in_array($column, FieldConfig::getReservedColumns()) ? $column : $field->getName() . '_' . $column; } - /** - * Gets the schema builder for this storage controller. - */ - protected function schemaBuilder() { - if (!isset($this->schemaBuilder)) { - $this->schemaBuilder = new ContentEntitySchemaHandler($this->entityManager, $this->entityType); - } - return $this->schemaBuilder; - } - - /** - * {@inheritdoc} - */ - public function getTableMapping() { - return $this->schemaBuilder()->getTableMapping(); - } - - /** - * {@inheritdoc} - */ - public function getSchema() { - return $this->schemaBuilder()->getSchema(); - } - } diff --git a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php index 463e84c..46ab0b7 100644 --- a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php +++ b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php @@ -8,6 +8,7 @@ use Drupal\Core\Entity\ContentEntityType; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\SqlStorageInterface; use Drupal\Core\Field\FieldDefinitionInterface; /** @@ -16,36 +17,6 @@ class ContentEntitySchemaHandler implements ContentEntitySchemaHandlerInterface { /** - * The base table layout: no revision or multilingual support for base fields. - * - * @var int - */ - const LAYOUT_BASE = 0; - - /** - * The revision table layout: provides revision support for base fields. - * - * @var int - */ - const LAYOUT_REV = 1; - - /** - * The multilingual table layout: provides multilingual support for base - * fields. - * - * @var int - */ - const LAYOUT_MUL = 2; - - /** - * The multilingual revision table layout: provides revision and multilingual - * support for base fields. - * - * @var int - */ - const LAYOUT_MULREV = 3; - - /** * The entity type this schema builder is responsible for. * * @var \Drupal\Core\Entity\ContentEntityType @@ -53,13 +24,6 @@ class ContentEntitySchemaHandler implements ContentEntitySchemaHandlerInterface protected $entityType; /** - * An array containing the entity type keys. - * - * @var array - */ - protected $entityKeys; - - /** * The base field definitions for this entity type. * * @var \Drupal\Core\Field\FieldDefinitionInterface[] @@ -67,18 +31,11 @@ class ContentEntitySchemaHandler implements ContentEntitySchemaHandlerInterface protected $fieldDefinitions; /** - * A mapping of schema fields that will be stored per entity table. - * - * @var array - */ - protected $tableMapping; - - /** - * The table layout associated to the entity type. + * A table mapper for the given entity type. * - * @var int + * @var \Drupal\Core\Entity\SqlStorageInterface */ - protected $layoutType; + protected $mapper; /** * A static cache of the generated schema array. @@ -95,174 +52,10 @@ class ContentEntitySchemaHandler implements ContentEntitySchemaHandlerInterface * @param \Drupal\Core\Entity\ContentEntityType $entity_type * The entity type. */ - public function __construct(EntityManagerInterface $entity_manager, ContentEntityType $entity_type) { + public function __construct(EntityManagerInterface $entity_manager, ContentEntityType $entity_type, SqlStorageInterface $mapper) { $this->entityType = $entity_type; $this->fieldDefinitions = $entity_manager->getBaseFieldDefinitions($entity_type->id()); - - $this->entityKeys = array_filter(array( - 'id' => $this->entityType->getKey('id'), - 'revision' => $this->entityType->getKey('revision'), - 'bundle' => $this->entityType->getKey('bundle'), - 'uuid' => $this->entityType->getKey('uuid'), - )); - // @todo This will become unnecessary once https://drupal.org/node/2143729 - // has landed. - if ($this->entityType->getDataTable()) { - $this->entityKeys['langcode'] = 'langcode'; - $this->entityKeys['default_langcode'] = 'default_langcode'; - } - } - - /** - * Returns the current layout type. - * - * @return int - * An integer value identifiying the current layour type. - * - * @see static::LAYOUT_BASE - * @see static::LAYOUT_REV - * @see static::LAYOUT_MUL - * @see static::LAYOUT_MULREV - */ - public function getLayoutType() { - if (!isset($this->layoutType)) { - $this->layoutType = static::LAYOUT_BASE; - if ($this->entityType->hasKey('revision')) { - $this->layoutType |= static::LAYOUT_REV; - } - if ($this->entityType->isTranslatable()) { - $this->layoutType |= static::LAYOUT_MUL; - } - } - return $this->layoutType; - } - - /** - * {@inheritdoc} - */ - public function getTableMapping() { - if (!isset($this->tableMapping)) { - $tables = $this->getTables(); - - if (empty($tables)) { - $table_mapping = array(); - } - // @todo Remove this. This is currently needed because some entity types - // declare a schema that does not match their field definitions. - // Therefore we use the legacy schema if it's still declared. This - // allows to iteratively enable the automatic schema generation for all - // entity types. - elseif ($base_schema = drupal_get_schema($tables['base_table'])) { - foreach (array_keys($base_schema['fields']) as $field_name) { - $table_mapping['base_table'][$field_name] = array($field_name); - } - if (isset($tables['revision_table'])) { - foreach (array_keys(drupal_get_schema($tables['revision_table'])['fields']) as $field_name) { - $table_mapping['revision_table'][$field_name] = array($field_name); - } - } - if (isset($tables['data_table'])) { - foreach (array_keys(drupal_get_schema($tables['data_table'])['fields']) as $field_name) { - $table_mapping['data_table'][$field_name] = array($field_name); - } - } - if (isset($tables['revision_data_table'])) { - foreach (array_keys(drupal_get_schema($tables['revision_data_table'])['fields']) as $field_name) { - $table_mapping['revision_data_table'][$field_name] = array($field_name); - } - } - } - else { - $entity_keys = $this->entityKeys; - unset($entity_keys['default_langcode']); - $key_fields = array_values($entity_keys); - - $storable_definitions = array_filter($this->fieldDefinitions, function (FieldDefinitionInterface $field_definition) { - return !$field_definition->isComputed() && !$field_definition->hasCustomStorage(); - }); - $storable_fields = array_keys($storable_definitions); - - // @todo Provide automatic definitions for revision metadata fields. - // Rename 'log' to 'revision_log'. - $revision_metadata_fields = array('revision_timestamp', 'revision_uid', 'log'); - $revisionable_filter_callback = function (FieldDefinitionInterface $definition) { return $definition->isRevisionable(); }; - - $this->getLayoutType(); - switch (TRUE) { - // The base layout stores all the base field values in the base table. - case $this->layoutType == static::LAYOUT_BASE: - $table_mapping['base_table'] = $this->processFields(array_merge($key_fields, array_diff($storable_fields, $key_fields))); - break; - - // The base layout stores all the base field values in the base table. - // Revisionable fields are also stored in the revision table. - case $this->layoutType == static::LAYOUT_REV: - $table_mapping['base_table'] = $this->processFields(array_merge($key_fields, array_diff($storable_fields, $key_fields, $revision_metadata_fields))); - $revision_key_fields = array($this->entityKeys['id'], $this->entityKeys['revision']); - $revisionable_fields = array_keys(array_filter($storable_definitions, $revisionable_filter_callback)); - $table_mapping['revision_table'] = $this->processFields(array_merge($revision_key_fields, $revisionable_fields)); - break; - - // Multilingual layouts store key field values in the base table. The - // other base field values are stored in the data table, no matter - // whether they are translatable or not. The data table holds also a - // denormalized copy of the bundle field value to allow for more - // performant queries. - case $this->layoutType == static::LAYOUT_MUL: - $table_mapping['base_table'] = $this->processFields($key_fields); - $data_key_fields = array_diff($key_fields, array('uuid')); - $data_fields = array_diff($storable_fields, $key_fields); - $table_mapping['data_table'] = $this->processFields(array_merge($data_key_fields, $data_fields)); - break; - - // The revisionable multilingual layout stores key field values in the - // base table, except for language, which is stored in the revision - // table along with revision metadata. The revision data table holds - // data field values for all the available revisions without - // denormalizations. - case $this->layoutType == static::LAYOUT_MULREV: - $table_mapping['base_table'] = $this->processFields(array_diff($key_fields, array($this->entityKeys['langcode']))); - $data_key_fields = array_diff($key_fields, array('uuid')); - $data_fields = array_diff($storable_fields, $key_fields, $revision_metadata_fields); - $table_mapping['data_table'] = $this->processFields(array_merge($data_key_fields, $data_fields)); - $table_mapping['revision_table'] = $this->processFields(array_merge(array($this->entityKeys['id'], $this->entityKeys['revision'], $this->entityKeys['langcode']), $revision_metadata_fields)); - $revision_data_key_fields = array_diff($key_fields, array($this->entityKeys['bundle'], $this->entityKeys['uuid'])); - $revisionable_fields = array_keys(array_filter($storable_definitions, $revisionable_filter_callback)); - $revision_data_fields = array_diff($revisionable_fields, $revision_metadata_fields, $revision_data_key_fields); - $table_mapping['revision_data_table'] = $this->processFields(array_merge($revision_data_key_fields, $revision_data_fields)); - break; - } - } - - $this->tableMapping = $table_mapping; - } - - return $this->tableMapping; - } - - /** - * Returns a mapping between field and column names. - * - * @param array $field_names - * An array of names of fields to map. - * - * @return array - * An associative array of arrays of column names keyed by field name. - */ - protected function processFields($field_names) { - $mapping = array(); - foreach ($field_names as $field_name) { - $columns = isset($this->fieldDefinitions[$field_name]) ? array_keys($this->fieldDefinitions[$field_name]->getColumns()) : array(); - if (count($columns) > 1) { - foreach ($columns as $column) { - $mapping[$field_name][] = $field_name . '__' . $column; - } - } - else { - $mapping[$field_name] = array($field_name); - } - } - return $mapping; + $this->mapper = $mapper; } /** @@ -304,9 +97,8 @@ public function getSchema() { } // Add the schema from field definitions. - foreach ($this->getTableMapping() as $table_key => $field_names) { + foreach ($this->mapper->getTableMapping() as $table => $field_names) { foreach ($field_names as $field_name => $column_names) { - $table = $tables[$table_key]; $this->addFieldSchema($schema[$table], $field_name); } } @@ -359,11 +151,12 @@ protected function addFieldSchema(array &$schema, $field_name) { $field_definition = $this->fieldDefinitions[$field_name]; $field_schema = $field_definition->getSchema(); if (count($field_schema['columns']) == 1) { + $schema['fields'][$field_name] = $field_schema['columns'][$field_definition->getMainPropertyName()]; $schema['fields'][$field_name]['description'] = $field_definition->getDescription(); // Only entity keys are required. - $schema['fields'][$field_name]['not null'] = !empty($this->entityKeys[$field_name]); + $schema['fields'][$field_name]['not null'] = (bool) $this->entityType->getKey($field_name); if (!empty($field_schema['unique keys'])) { $schema['unique keys'][$field_name] = array($field_name); @@ -381,7 +174,7 @@ protected function addFieldSchema(array &$schema, $field_name) { else { foreach ($field_schema['columns'] as $column_name => $column_schema) { // Only entity keys are required. - $column_schema['not null'] = !empty($this->entityKeys[$field_name]); + $column_schema['not null'] = (bool) $this->entityType->getKey($field_name); $schema['fields'][$field_name . '__' . $column_name] = $column_schema; } } @@ -413,7 +206,7 @@ protected function getDefaultLangcodeSchema() { protected function initializeBaseTable() { return array( 'description' => "The base table for {$this->entityType->id()} entities.", - 'primary key' => array($this->entityKeys['id']), + 'primary key' => array($this->entityType->getKey('id')), ); } @@ -424,10 +217,10 @@ protected function initializeBaseTable() { * A partial schema array for the revision table. */ protected function initializeRevisionTable() { - $id_key = $this->entityKeys['id']; + $id_key = $this->entityType->getKey('id'); return array( 'description' => "The revision table for {$this->entityType->id()} entities.", - 'primary key' => array($this->entityKeys['revision']), + 'primary key' => array($this->entityType->getKey('revision')), 'foreign keys' => array( $id_key => array( 'table' => $this->entityType->getBaseTable(), @@ -444,8 +237,7 @@ protected function initializeRevisionTable() { * A partial schema array for the data table. */ protected function initializeDataTable() { - $id_key = $this->entityKeys['id']; - + $id_key = $this->entityType->getKey('id'); return array( 'description' => "The data table for {$this->entityType->id()} entities.", // @todo Use the language entity key when https://drupal.org/node/2143729 @@ -467,8 +259,8 @@ protected function initializeDataTable() { * A partial schema array for the revision data table. */ protected function initializeRevisionDataTable() { - $id_key = $this->entityKeys['id']; - $revision_key = $this->entityKeys['revision'];; + $id_key = $this->entityType->getKey('id'); + $revision_key = $this->entityType->getKey('revision'); return array( 'description' => "The revision data table for {$this->entityType->id()} entities.", // @todo Use the language entity key when https://drupal.org/node/2143729 @@ -497,7 +289,7 @@ protected function initializeRevisionDataTable() { * A partial schema array for the base table. */ protected function processBaseTable(array &$schema) { - $id_key = $this->entityKeys['id']; + $id_key = $this->entityType->getKey('id'); // Change the ID field in the base table to 'serial' if it is 'int'. if ($schema['fields'][$id_key]['type'] == 'int') { $schema['fields'][$id_key]['type'] = 'serial'; @@ -515,7 +307,7 @@ protected function processBaseTable(array &$schema) { * A partial schema array for the base table. */ protected function processRevisionTable(array &$schema) { - $revision_key = $this->entityKeys['revision']; + $revision_key = $this->entityType->getKey('revision'); // Change the revision ID field in the revision table 'serial' if it is // 'int'. if ($schema['fields'][$revision_key]['type'] == 'int') { diff --git a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandlerInterface.php b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandlerInterface.php index 0be1b3d..5b958d8 100644 --- a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandlerInterface.php +++ b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandlerInterface.php @@ -11,16 +11,6 @@ interface ContentEntitySchemaHandlerInterface { /** - * Gets a mapping of schema fields that will be stored per entity table. - * - * @return array - * An nested array where the keys are the names of the entity tables and the - * values are arrays containing the names of the fields that will be stored - * in the respective tables. - */ - public function getTableMapping(); - - /** * Gets the full schema array for a given entity type. * * @return array diff --git a/core/lib/Drupal/Core/Entity/SqlStorageInterface.php b/core/lib/Drupal/Core/Entity/SqlStorageInterface.php index e58075d..4bff3c2 100644 --- a/core/lib/Drupal/Core/Entity/SqlStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/SqlStorageInterface.php @@ -6,10 +6,19 @@ namespace Drupal\Core\Entity; -use Drupal\Core\Entity\Schema\ContentEntitySchemaHandlerInterface; - /** * A common interface for SQL-based storage controllers. */ -interface SqlStorageInterface extends EntityStorageInterface, ContentEntitySchemaHandlerInterface { +interface SqlStorageInterface { + + /** + * Gets a mapping of schema fields that will be stored per entity table. + * + * @return array + * An nested array where the keys are the names of the entity tables and the + * values are arrays containing the names of the fields that will be stored + * in the respective tables. + */ + public function getTableMapping(); + } diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index 7ed6d46..cb872b7 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -9,7 +9,7 @@ */ use Drupal\Core\Config\Entity\ConfigEntityStorage; -use Drupal\Core\Entity\SqlStorageInterface; +use Drupal\Core\Entity\Schema\ContentEntitySchemaHandlerInterface; /** * Implements hook_help(). @@ -112,7 +112,7 @@ function entity_modules_installed($modules) { foreach ($definitions as $entity_type_id => $entity_type) { if ($entity_type->getProvider() == $module) { $storage = $entity_manager->getStorage($entity_type_id); - if ($storage instanceof SqlStorageInterface) { + if ($storage instanceof ContentEntitySchemaHandlerInterface) { foreach ($storage->getSchema() as $table_name => $table_schema) { // Some test entity types share the same schema so we need a check to // avoid attempting to create the schema more than once, which would @@ -157,7 +157,7 @@ function entity_modules_uninstalled($modules) { if ($entity_type->getProvider() == $module) { // Remove entity tables. $storage = $entity_manager->getStorage($entity_type->id()); - if ($storage instanceof SqlStorageInterface) { + if ($storage instanceof ContentEntitySchemaHandlerInterface) { foreach ($storage->getSchema() as $table_name => $table_schema) { // @todo Remove the drupal_get_schema() call once all entity types // have been converted to an automatic schema. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 9585ff7..5d89844 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DrupalKernel; -use Drupal\Core\Entity\SqlStorageInterface; +use Drupal\Core\Entity\Schema\ContentEntitySchemaHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueMemoryFactory; use Drupal\Core\Language\Language; use Symfony\Component\DependencyInjection\Reference; @@ -346,7 +346,7 @@ protected function installEntitySchema($entity_type_id) { $schema_handler = $this->container->get('database')->schema(); $storage = $entity_manager->getStorage($entity_type_id); - if ($storage instanceof SqlStorageInterface) { + if ($storage instanceof ContentEntitySchemaHandlerInterface) { $schema = $storage->getSchema(); foreach ($schema as $table_name => $table_schema) { $schema_handler->createTable($table_name, $table_schema);