diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index 9aeffb5..18e4334 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -166,12 +166,17 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa $this->revisionKey = $this->entityType->getKey('revision') ?: 'revision_id'; $this->revisionTable = $this->entityType->getRevisionTable() ?: $this->entityTypeId . '_revision'; } - if ($this->entityType->isTranslatable()) { + // @todo Remove the data table check once all entity types are using + // entity query and we have a views data controller. See: + // - https://drupal.org/node/2068325 + // - https://drupal.org/node/1740492 + $translatable = $this->entityType->getDataTable() && $this->entityType->isTranslatable(); + if ($translatable) { $this->dataTable = $this->entityType->getDataTable() ?: $this->entityTypeId . '_field_data'; $this->langcodeKey = $this->entityType->getKey('langcode') ?: 'langcode'; $this->defaultLangcodeKey = $this->entityType->getKey('default_langcode') ?: 'default_langcode'; } - if ($this->entityType->hasKey('revision') && $this->entityType->isTranslatable()) { + if ($this->entityType->hasKey('revision') && $translatable) { $this->revisionDataTable = $this->entityType->getRevisionDataTable() ?: $this->entityTypeId . '_field_revision'; } } @@ -259,11 +264,16 @@ public function getTableMapping() { // https://drupal.org/node/2248991. $revision_metadata_fields = array_intersect(array('revision_timestamp', 'revision_uid', 'log'), $all_fields); - if (!$this->entityType->hasKey('revision') && !$this->entityType->isTranslatable()) { + // @todo Remove the data table check once all entity types are using + // entity query and we have a views data controller. See: + // - https://drupal.org/node/2068325 + // - https://drupal.org/node/1740492 + $translatable = $this->entityType->getDataTable() && $this->entityType->isTranslatable(); + if (!$this->entityType->hasKey('revision') && !$translatable) { // The base layout stores all the base field values in the base table. $this->tableMapping->addFieldColumns($this->baseTable, $all_fields); } - elseif ($this->entityType->hasKey('revision') && !$this->entityType->isTranslatable()) { + elseif ($this->entityType->hasKey('revision') && !$translatable) { // The revisionable layout stores all the base field values in the base // table, except for revision metadata fields. Revisionable fields // denormalized in the base table but also stored in the revision table @@ -273,7 +283,7 @@ public function getTableMapping() { $revision_key_fields = array($this->idKey, $this->revisionKey); $this->tableMapping->addFieldColumns($this->revisionTable, array_merge($revision_key_fields, $revisionable_fields)); } - elseif (!$this->entityType->hasKey('revision') && $this->entityType->isTranslatable()) { + elseif (!$this->entityType->hasKey('revision') && $translatable) { // 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 @@ -288,7 +298,7 @@ public function getTableMapping() { // "base_table.langcode = data_table.langcode" ->addExtraColumns($this->dataTable, array('default_langcode')); } - elseif ($this->entityType->hasKey('revision') && $this->entityType->isTranslatable()) { + elseif ($this->entityType->hasKey('revision') && $translatable) { // 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 diff --git a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php index bef9e39..dc31797 100644 --- a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php +++ b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php @@ -147,9 +147,10 @@ protected function addFieldSchema(array &$schema, $field_name, array $column_map $schema['fields'][$schema_field_name] = $column_schema; $schema['fields'][$schema_field_name]['description'] = $field_description; + // @todo This does not work. // Only entity keys are required. $keys = $this->entityType->getKeys() + array('langcode' => 'langcode'); - $schema['fields'][$schema_field_name]['not null'] = in_array($field_name, $keys); + $schema['fields'][$schema_field_name]['not null'] = FALSE && in_array($field_name, $keys); } if (!empty($field_schema['indexes'])) {