diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index f276e8d..f0ff2ae 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -269,7 +269,7 @@ public function setEntityType(ContentEntityTypeInterface $entity_type) { /** * {@inheritdoc} */ - public function getTableMapping($storage_definitions = NULL) { + public function getTableMapping(array $storage_definitions = NULL) { $table_mapping = $this->tableMapping; if (!isset($this->tableMapping) || $storage_definitions) { @@ -1442,6 +1442,9 @@ public function onEntityTypeDefinitionUpdate(EntityTypeInterface $original) { public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) { // If we are adding a field stored in a shared table we need to recompute // the table mapping. + // @todo This does not belong here. Remove it once we are able to generate a + // fresh table mapping in the schema handler. See + // https://www.drupal.org/node/2274017. if ($this->getTableMapping()->allowsSharedTableStorage($storage_definition)) { $this->tableMapping = NULL; } diff --git a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php index 22581d8..f950887 100644 --- a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php +++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php @@ -113,6 +113,8 @@ public function getAllColumns($table_name) { // There is just one field for each dedicated storage table, thus // $field_name can only refer to it. if (isset($field_name) && $this->requiresDedicatedTableStorage($this->fieldStorageDefinitions[$field_name])) { + // Unlike in shared storage tables, in dedicated ones field columns are + // positioned last. $this->allColumns[$table_name] = array_merge($this->getExtraColumns($table_name), $this->allColumns[$table_name]); } else { diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php b/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php index 1a4e0bc..02174bf 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php @@ -17,9 +17,13 @@ /** * Gets a table mapping for the entity's SQL tables. * + * @param \Drupal\Core\Field\FieldStorageDefinitionInterface[] $storage_definitions + * (optional) An array of field storage definitions to be used to compute + * the table mapping. Defaults to the ones provided by the entity manager. + * * @return \Drupal\Core\Entity\Sql\TableMappingInterface * A table mapping object for the entity's tables. */ - public function getTableMapping(); + public function getTableMapping(array $storage_definitions = NULL); } diff --git a/core/tests/Drupal/Tests/Core/Entity/Schema/ContentEntitySchemaHandlerTest.php b/core/tests/Drupal/Tests/Core/Entity/Schema/ContentEntitySchemaHandlerTest.php index 932c5b8..1a4bb1f 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Schema/ContentEntitySchemaHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Schema/ContentEntitySchemaHandlerTest.php @@ -776,7 +776,7 @@ public function testDedicatedTableSchema() { )); // Setup a field having a dedicated schema. - $field_name = $this->randomName(); + $field_name = $this->getRandomGenerator()->name(); $this->setUpStorageDefinition($field_name, array( 'columns' => array( 'shape' => array(