diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 067f307..e321e00 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -750,7 +750,6 @@ public function addTranslation($langcode, array $values = array()) { // Instantiate a new empty entity so default values will be populated in the // specified language. - $entity_type = $this->getEntityType(); $default_values = array( diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index f276dd5..0599860 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -54,11 +54,11 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase { /** * Name of entity's default language database table field. * - * Has the value FALSE if this entity does not have multilingual support. + * Is only set if the entity has multilingual support. * * @var string */ - protected $defaultLanguageKey = 'default_langcode'; + protected $defaultLangcodeKey; /** * The table that stores revision field data if the entity supports revisions. @@ -132,6 +132,9 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa // Check if the entity type has a dedicated table for fields. if ($data_table = $this->entityType->getDataTable()) { $this->dataTable = $data_table; + // Instead of hardcoding this value throughout this class, we store it in + // a member variable to allow subclasses to override this. + $this->defaultLangcodeKey = 'default_langcode'; // Entity types having both revision and translation support should always // define a revision data table. if ($this->revisionTable && $revision_data_table = $this->entityType->getRevisionDataTable()) { @@ -289,7 +292,7 @@ protected function attachPropertyData(array &$entities) { // Field values in default language are stored with // Language::LANGCODE_DEFAULT as key. - $langcode = empty($values[$this->defaultLanguageKey]) ? $values[$this->langcodeKey] : Language::LANGCODE_DEFAULT; + $langcode = empty($values[$this->defaultLangcodeKey]) ? $values[$this->langcodeKey] : Language::LANGCODE_DEFAULT; $translations[$id][$langcode] = TRUE; foreach (array_keys($field_definitions) as $field_name) { @@ -367,13 +370,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($this->defaultLanguageKey, $values)) { - $values[$this->defaultLanguageKey] = 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[$this->defaultLanguageKey] === NULL) { - unset($values[$this->defaultLanguageKey]); + elseif ($values[$this->defaultLangcodeKey] === NULL) { + unset($values[$this->defaultLangcodeKey]); } } diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index c976e30..b9974c6 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -248,7 +248,6 @@ public function getKeys() { 'revision' => '', 'bundle' => '', 'langcode' => '', - 'default_language' => '', ); } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 9ba3be6..51da949 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -93,10 +93,6 @@ public function getClass(); * - langcode: (optional) The name of the property that contains the * language code. For instance, if the entity's language is located in * $entity->language, then 'language' should be specified here. - * - default_language: (optional) The name of the database column that - * stores whether a language variant belongs to the default language of - * the entity. This entry can be omitted if this entity type is not - * translatable. * - bundle: (optional) The name of the property that contains the bundle * name for the entity. The bundle name defines which set of fields are * attached to the entity (e.g. what nodes call "content type"). This diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index b7ea7c7..98afaf1 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -82,9 +82,9 @@ public function testHasKey($entity_keys, $expected) { */ public function providerTestGetKeys() { return array( - array(array(), array('revision' => '', 'bundle' => '', 'langcode' => '', 'default_language' => '')), - array(array('id' => 'id'), array('id' => 'id', 'revision' => '', 'bundle' => '', 'langcode' => '', 'default_language' => '')), - array(array('bundle' => 'bundle'), array('bundle' => 'bundle', 'revision' => '', 'langcode' => '', 'default_language' => '')), + array(array(), array('revision' => '', 'bundle' => '', 'langcode' => '')), + array(array('id' => 'id'), array('id' => 'id', 'revision' => '', 'bundle' => '', 'langcode' => '')), + array(array('bundle' => 'bundle'), array('bundle' => 'bundle', 'revision' => '', 'langcode' => '')), ); }