diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index b4aaba7..81281ed 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -515,18 +515,26 @@ protected function loadFromSharedTables(array &$values, array &$translations) { // Find revisioned fields that are not entity keys. Exclude the langcode // key as the base table holds only the default language. $base_fields = array_diff($table_mapping->getFieldNames($this->baseTable), array($this->langcodeKey)); - $fields = array_diff($table_mapping->getFieldNames($this->revisionDataTable), $base_fields); + $revisioned_fields = array_diff($table_mapping->getFieldNames($this->revisionDataTable), $base_fields); // Find fields that are not revisioned or entity keys. Data fields have // the same value regardless of entity revision. - $data_fields = array_diff($table_mapping->getFieldNames($this->dataTable), $fields, $base_fields); + $data_fields = array_diff($table_mapping->getFieldNames($this->dataTable), $revisioned_fields, $base_fields); + // If there are no data fields then only revisioned fields are needed + // else both data fields and revisioned fields are needed to map the + // entity values. + $fields = $revisioned_fields; if ($data_fields) { - $fields = array_merge($fields, $data_fields); + $fields = array_merge($revisioned_fields, $data_fields); $query->leftJoin($this->dataTable, 'data', "(revision.$this->idKey = data.$this->idKey)"); $column_names = []; // Some fields can have more then one columns in the data table so // column names are needed. foreach ($data_fields as $data_field) { + // \Drupal\Core\Entity\Sql\TableMappingInterface:: getColumNames() + // returns an array keyed by property names so remove the keys + // before array_merge() to avoid losing data with fields having the + // same columns i.e. value. $column_names = array_merge($column_names, array_values($table_mapping->getColumnNames($data_field))); } $query->fields('data', $column_names); diff --git a/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php b/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php index 3c553bf..31c3385 100644 --- a/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php +++ b/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php @@ -45,7 +45,11 @@ public function getTableNames(); public function getAllColumns($table_name); /** - * Gets a list of names of fields stored in the specified table. + * Gets a list of names for entity fields stored in the specified table. + * + * The return list is contains the entity field names, not database field + * (i.e. column) names. To get the mapping of specific entity field to + * database columns use ::getColumnNames(). * * @param string $table_name * The name of the table to return the field names for.