diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index f0fcac8..76582bb 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -471,13 +471,24 @@ protected function buildBaseFieldDefinitions($entity_type_id) { // Ensure defined entity keys are there and have proper revisionable and // translatable values. - $fixed_keys = array('id', 'revision', 'uuid', 'bundle'); - foreach ($keys as $key => $field_name) { - if (isset($base_field_definitions[$field_name]) && in_array($key, $fixed_keys) && $base_field_definitions[$field_name]->isRevisionable()) { - throw new \LogicException(String::format('The @field field cannot be revisionable as it is used as @key entity key.', array('@field' => $base_field_definitions[$field_name]->getLabel(), '@key' => $key))); + foreach (array_intersect_key($keys, array_flip(['id', 'revision', 'uuid', 'bundle'])) as $key => $field_name) { + if (!isset($base_field_definitions[$field_name])) { + throw new \LogicException(String::format('The @field field definition does not exist and it is used as @key entity key.', array( + '@field' => $base_field_definitions[$field_name]->getLabel(), + '@key' => $key + ))); } - if (isset($base_field_definitions[$field_name]) && in_array($key, $fixed_keys) && $base_field_definitions[$field_name]->isTranslatable()) { - throw new \LogicException(String::format('The @field field cannot be translatable as it is used as @key entity key.', array('@field' => $base_field_definitions[$field_name]->getLabel(), '@key' => $key))); + if ($base_field_definitions[$field_name]->isRevisionable()) { + throw new \LogicException(String::format('The @field field cannot be revisionable as it is used as @key entity key.', array( + '@field' => $base_field_definitions[$field_name]->getLabel(), + '@key' => $key + ))); + } + if ($base_field_definitions[$field_name]->isTranslatable()) { + throw new \LogicException(String::format('The @field field cannot be translatable as it is used as @key entity key.', array( + '@field' => $base_field_definitions[$field_name]->getLabel(), + '@key' => $key + ))); } } diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php index 5b6af02..08674f2 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php @@ -193,7 +193,13 @@ public function getFields($include_computed = TRUE); * @param string $field_name * The name of the field which is changed. * + * @throws \InvalidArgumentException + * When trying to assign a value to the language field that matches an + * existing translation. * @throws \LogicException + * When trying to change: + * - the language of a translation; + * - the value of the flag identifying the default translation object. */ public function onChange($field_name);