diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index d29846a..4c9b184 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -253,8 +253,6 @@ public function isDefaultRevision($new_value = NULL) { /** * {@inheritdoc} - * - * TODO */ public function isDefaultTranslation() { return $this->activeLangcode == Language::LANGCODE_DEFAULT; @@ -704,7 +702,7 @@ public function addTranslation($langcode, array $values = array()) { } } $values[$this->langcodeKey] = $langcode; - $values['default_langcode'] = FALSE; + $values[$this->getEntityType()->getKey('default_langcode')] = FALSE; $this->translations[$langcode]['status'] = static::TRANSLATION_CREATED; $translation = $this->getTranslation($langcode); diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index cfa970a..a6fe80f 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -411,7 +411,7 @@ protected function buildBaseFieldDefinitions($entity_type_id) { // Retrieve base field definitions and assign them the entity type provider. /** @var FieldStorageDefinitionInterface[] $base_field_definitions */ $base_field_definitions = $class::baseFieldDefinitions($entity_type); - $name = !empty($keys['default_langcode']) ? $keys['default_langcode'] : 'default_langcode'; + $name = $keys['default_langcode']; if ($entity_type->isTranslatable() && !isset($base_field_definitions[$name])) { $base_field_definitions[$name] = BaseFieldDefinition::create('boolean') ->setLabel($this->t('Default translation')) diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 0c09ec9..6e1ecf1 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -182,8 +182,8 @@ public function addField($field, $type, $langcode) { $table = $this->ensureEntityTable($index_prefix, $sql_column, $type, $langcode, $base_table, $entity_id_field, $entity_tables); - // If there is a field storage (some specifiers are not, like - // default_langcode), check for case sensitivity. + // If there is a field storage (some specifiers are not), check for case + // sensitivity. if ($field_storage) { $column = $field_storage->getMainPropertyName(); $base_field_property_definitions = $field_storage->getPropertyDefinitions(); diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index ccb8fb9..5968446 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -67,6 +67,13 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt protected $langcodeKey = FALSE; /** + * The default language entity key. + * + * @var string + */ + protected $defaultLangcodeKey = FALSE; + + /** * The base table of the entity. * * @var string @@ -200,7 +207,7 @@ protected function initTableLayout() { if ($translatable) { $this->dataTable = $this->entityType->getDataTable() ?: $this->entityTypeId . '_field_data'; $this->langcodeKey = $this->entityType->getKey('langcode'); - $this->defaultLangcodeKey = $this->entityType->getKey('default_langcode') ?: 'default_langcode'; + $this->defaultLangcodeKey = $this->entityType->getKey('default_langcode'); } if ($revisionable && $translatable) { $this->revisionDataTable = $this->entityType->getRevisionDataTable() ?: $this->entityTypeId . '_field_revision'; @@ -690,7 +697,7 @@ protected function attachPropertyData(array &$entities) { // Field values in default language are stored with // LanguageInterface::LANGCODE_DEFAULT as key. - $langcode = empty($values['default_langcode']) ? $values[$this->langcodeKey] : LanguageInterface::LANGCODE_DEFAULT; + $langcode = empty($values[$this->defaultLangcodeKey]) ? $values[$this->langcodeKey] : LanguageInterface::LANGCODE_DEFAULT; $translations[$id][$langcode] = TRUE; foreach ($fields as $field_name) { @@ -762,13 +769,13 @@ protected function buildPropertyQuery(QueryInterface $entity_query, array $value // apply to the default language. See http://drupal.org/node/1866330. // Default to the original entity language if not explicitly specified // otherwise. - if (!array_key_exists('default_langcode', $values)) { - $values['default_langcode'] = 1; + if (!array_key_exists($this->defaultLangcodeKey, $values)) { + $values[$this->defaultLangcodeKey] = 1; } // If the 'default_langcode' flag is explicitly not set, we do not care // whether the queried values are in the original entity language or not. - elseif ($values['default_langcode'] === NULL) { - unset($values['default_langcode']); + elseif ($values[$this->defaultLangcodeKey] === NULL) { + unset($values[$this->defaultLangcodeKey]); } } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index b4b745b..4a399a3 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -515,13 +515,6 @@ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $res $schema[$table_name] = array_merge_recursive($schema[$table_name], $this->getSharedTableFieldSchema($storage_definition, $table_name, $column_names)); } } - - // Add the schema for extra fields. - foreach ($table_mapping->getExtraColumns($table_name) as $column_name) { - if ($column_name == 'default_langcode') { - $this->addDefaultLangcodeSchema($schema[$table_name]); - } - } } // Process tables after having gathered field information. @@ -736,25 +729,6 @@ protected function getFieldForeignKeys($field_name, array $field_schema, array $ } /** - * Returns the schema for the 'default_langcode' metadata field. - * - * @param array $schema - * The table schema to add the field schema to, passed by reference. - * - * @return array - * A schema field array for the 'default_langcode' metadata field. - */ - protected function addDefaultLangcodeSchema(&$schema) { - $schema['fields']['default_langcode'] = array( - 'description' => 'Boolean indicating whether field values are in the default entity language.', - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 1, - ); - } - - /** * Loads stored schema data for the given entity type definition. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type diff --git a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php index b3b832b..73b288d 100644 --- a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php +++ b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php @@ -13,7 +13,7 @@ interface TranslatableInterface { /** - * Returns the default language. + * Returns the translation language. * * @return \Drupal\Core\Language\LanguageInterface * The language object. @@ -21,6 +21,14 @@ public function language(); /** + * Checks whether the translation is the default one. + * + * @return bool + * TRUE if the translation is the default one, FALSE otherwise. + */ + public function isDefaultTranslation(); + + /** * Returns the languages the data is translated to. * * @param bool $include_default diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 895a66b..179b8ad 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -779,7 +779,7 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f ->will($this->returnValue($entity_class)); $this->entityType->expects($this->any()) ->method('getKeys') - ->will($this->returnValue($entity_keys)); + ->will($this->returnValue($entity_keys + array('default_langcode' => 'default_langcode'))); $this->entityType->expects($this->any()) ->method('isSubclassOf') ->with($this->equalTo('\Drupal\Core\Entity\FieldableEntityInterface')) @@ -1102,7 +1102,7 @@ public function testGetFieldMap() { ->will($this->returnValue($entity_class)); $entity_type->expects($this->any()) ->method('getKeys') - ->will($this->returnValue(array())); + ->will($this->returnValue(array('default_langcode' => 'default_langcode'))); $entity_type->expects($this->any()) ->method('id') ->will($this->returnValue('test_entity_type')); @@ -1245,7 +1245,7 @@ public function testGetFieldMapByFieldType() { ->will($this->returnValue($entity_class)); $entity_type->expects($this->any()) ->method('getKeys') - ->will($this->returnValue(array())); + ->will($this->returnValue(array('default_langcode' => 'default_langcode'))); $entity_type->expects($this->any()) ->method('id') ->will($this->returnValue('test_entity_type')); diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php index 9a786d5..237435f 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -89,7 +89,6 @@ protected function setUp() { * @covers ::getFieldUniqueKeys * @covers ::getFieldForeignKeys * @covers ::getFieldSchemaData - * @covers ::addDefaultLangcodeSchema * @covers ::processBaseTable * @covers ::processIdentifierSchema */ @@ -321,13 +320,6 @@ public function testGetSchemaBase() { 'type' => 'int', 'not null' => FALSE, ), - 'default_langcode' => array( - 'description' => 'Boolean indicating whether field values are in the default entity language.', - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 1, - ), ), 'primary key' => array('id'), 'unique keys' => array(