diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index a988135..9d9cfd7 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -8,8 +8,10 @@ namespace Drupal\Core\Config\Entity; use Drupal\Core\Entity\Entity; +use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Config\ConfigDuplicateUUIDException; +use Drupal\Core\Entity\EntityTypeMalformedException; /** * Defines a base configuration entity class. @@ -48,6 +50,13 @@ public function __construct(array $values, $entity_type) { parent::__construct($values, $entity_type); + // The configuration translation system relies on the 'langcode' key to + // perform language detection and overrides. Therefore it is not valid to + // set the language entity key to anything other than 'langcode'. + if ($this->entityInfo()->getKey('langcode') != 'langcode') { + throw new EntityTypeMalformedException("The entity type '$entity_type' has an invalid 'langcode' entity key."); + } + // Backup the original ID, if any. // Configuration entity IDs are strings, and '0' is a valid ID. $original_id = $this->id(); diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 6221633..80814cc 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -353,11 +353,12 @@ public function getFieldDefinitions($entity_type, $bundle = NULL) { $this->moduleHandler->alter($hooks, $this->entityFieldInfo[$entity_type], $entity_type); // Ensure all basic fields are not defined as translatable. - $keys = array_intersect_key(array_filter($entity_info->getKeys()), array_flip(array('id', 'revision', 'uuid', 'bundle'))); - $untranslatable_fields = array_flip(array('langcode') + $keys); + // @todo I don't think this works as expected. I think it should + // array_flip additionally. + $untranslatable_fields = array_filter($entity_info->getKeys()); foreach (array('definitions', 'optional') as $key) { foreach ($this->entityFieldInfo[$entity_type][$key] as $field_name => &$definition) { - if (isset($untranslatable_fields[$field_name]) && $definition->isTranslatable()) { + if (in_array($field_name, $untranslatable_fields) && $definition->isTranslatable()) { throw new \LogicException(String::format('The @field field cannot be translatable.', array('@field' => $definition->getLabel()))); } } diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 9edc094..b784952 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -236,7 +236,11 @@ public function isFieldDataCacheable() { * {@inheritdoc} */ public function getKeys() { - return $this->entity_keys + array('revision' => '', 'bundle' => '', 'langcode' => 'langcode'); + return $this->entity_keys + array( + 'revision' => '', + 'bundle' => '', + 'langcode' => 'langcode', + ); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityTypeMalformedException.php b/core/lib/Drupal/Core/Entity/EntityTypeMalformedException.php index ab14448..f1f7cb3 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeMalformedException.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeMalformedException.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Entity\EntityMalformedException. + * Contains \Drupal\Core\Entity\EntityTypeMalformedException. */ namespace Drupal\Core\Entity; @@ -10,4 +10,4 @@ /** * Defines an exception thrown when a malformed entity is passed. */ -class EntityMalformedException extends \Exception { } +class EntityTypeMalformedException extends \Exception { } diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index 282987d..fac167f 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -284,7 +284,8 @@ protected function attachPropertyData(array &$entities) { // Field values in default language are stored with // Language::LANGCODE_DEFAULT as key. - $langcode = empty($values['default_langcode']) ? $values['langcode'] : Language::LANGCODE_DEFAULT; + $language_key = 'langcode'; + $langcode = empty($values["default_$language_key"]) ? $values[$language_key] : Language::LANGCODE_DEFAULT; $translations[$id][$langcode] = TRUE; foreach (array_keys($field_definitions) as $field_name) { @@ -362,13 +363,14 @@ 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; + $default_langcode_key = "default_{$this->langcode_key}"; + if (!array_key_exists($default_langcode_key, $values)) { + $values[$default_langcode_key] = 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[$default_langcode_key] === NULL) { + unset($values[$default_langcode_key]); } }