diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php index bdb592c..a55bc75 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php @@ -11,7 +11,7 @@ use Drupal\Core\TypedData\ContextAwareInterface; /** - * Defines the 'entityre_reference_field' entity field item. + * Defines the 'entityre_reference' entity field item. * * Required settings (below the definition's 'settings' key) are: * - target_type: The entity type to reference. @@ -31,6 +31,7 @@ class EntityReferenceItem extends FieldItemBase { * Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). */ public function getPropertyDefinitions() { + // Definitions vary by entity type, so key them by entity type. $target_type = $this->definition['settings']['target_type']; if (!isset(self::$propertyDefinitions[$target_type])) { diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index e9248b0..fcf3ef5 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -36,6 +36,10 @@ function entity_reference_field_info() { /** * Implements hook_entity_field_info(). + * + * Set the "target_type" property definition for entity reference fields. + * + * @see Drupal\Core\Entity\Field\Type\EntityReferenceItem::getPropertyDefinitions() */ function entity_reference_entity_field_info($entity_type) { $property_info = array(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php index 8995301..88a2509 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php @@ -81,9 +81,7 @@ function testCRUD() { $this->assertNotEqual($entity_duplicate->id(), $entity->id()); break; default: - // @todo: Use the property data to extract the key. - $key = $property == 'user_id' ? 'target_id' : 'value'; - $this->assertEqual($entity_duplicate->{$property}->{$key}, $entity->{$property}->{$key}); + $this->assertEqual($entity_duplicate->{$property}->getValue(), $entity->{$property}->getValue()); } } $entity_duplicate->save(); diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index 385480b..13afc7d 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -209,10 +209,7 @@ function translation_entity_prepare_translation(EntityInterface $entity, Languag $source_translation = $entity->getTranslation($source->langcode); $target_translation = $entity->getTranslation($target->langcode); foreach ($target_translation->getPropertyDefinitions() as $property_name => $definition) { - // @todo The "key" part should not be needed. Remove it as soon as things - // do not break. - $key = key($entity->{$property_name}[0]->getProperties()); - $target_translation->$property_name->{$key} = $source_translation->$property_name->{$key}; + $target_translation->$property_name = $source_translation->$property_name; } } else {