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 new file mode 100644 index 0000000..f1f7cb3 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityTypeMalformedException.php @@ -0,0 +1,13 @@ +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]); } }