diff --git a/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php b/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php
index d007bd93118..0fb0a0b04b6 100644
--- a/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php
+++ b/core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php
@@ -27,12 +27,18 @@ class EntityReferenceFieldItemNormalizer extends ComplexDataNormalizer {
public function normalize($field_item, $format = NULL, array $context = []) {
$values = parent::normalize($field_item, $format, $context);
- // Add a 'url' value if there is a reference and a canonical URL. Hard code
- // 'canonical' here as config entities override the default $rel parameter
- // value to 'edit-form.
/** @var \Drupal\Core\Entity\EntityInterface $entity */
- if (($entity = $field_item->get('entity')->getValue()) && ($url = $entity->url('canonical'))) {
- $values['url'] = $url;
+ if ($entity = $field_item->get('entity')->getValue()) {
+ $values['target_type'] = $entity->getEntityTypeId();
+ // Add the target entity UUID to the normalized output values.
+ $values['target_uuid'] = $entity->uuid();
+
+ // Add a 'url' value if there is a reference and a canonical URL. Hard
+ // code 'canonical' here as config entities override the default $rel
+ // parameter value to 'edit-form.
+ if ($url = $entity->url('canonical')) {
+ $values['url'] = $url;
+ }
}
return $values;
diff --git a/core/modules/serialization/src/Tests/EntitySerializationTest.php b/core/modules/serialization/src/Tests/EntitySerializationTest.php
index d9be353afa2..abcac0139f0 100644
--- a/core/modules/serialization/src/Tests/EntitySerializationTest.php
+++ b/core/modules/serialization/src/Tests/EntitySerializationTest.php
@@ -116,6 +116,8 @@ class EntitySerializationTest extends NormalizerTestBase {
'user_id' => array(
array(
'target_id' => $this->user->id(),
+ 'target_type' => $this->user->getEntityTypeId(),
+ 'target_uuid' => $this->user->uuid(),
'url' => $this->user->url(),
),
),
@@ -190,7 +192,7 @@ class EntitySerializationTest extends NormalizerTestBase {
'name' => '' . $this->values['name'] . '',
'type' => 'entity_test_mulrev',
'created' => '' . $this->entity->created->value . '',
- 'user_id' => '' . $this->user->id() . '' . $this->user->url() . '',
+ 'user_id' => '' . $this->user->id() . '' . $this->user->getEntityTypeId() . '' . $this->user->uuid() . '' . $this->user->url() . '',
'revision_id' => '' . $this->entity->getRevisionId() . '',
'default_langcode' => '1',
'field_test_text' => '' . $this->values['field_test_text']['value'] . '' . $this->values['field_test_text']['format'] . '',
diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
index a86b6f7e508..04cfa16a0d2 100644
--- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
+++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@@ -78,6 +78,12 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
$entity->url('canonical')
->willReturn($test_url)
->shouldBeCalled();
+ $entity->uuid()
+ ->willReturn('080e3add-f9d5-41ac-9821-eea55b7b42fb')
+ ->shouldBeCalled();
+ $entity->getEntityTypeId()
+ ->willReturn('test_type')
+ ->shouldBeCalled();
$entity_reference = $this->prophesize(TypedDataInterface::class);
$entity_reference->getValue()
@@ -92,6 +98,8 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
$expected = [
'target_id' => ['value' => 'test'],
+ 'target_type' => 'test_type',
+ 'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
'url' => $test_url,
];
$this->assertSame($expected, $normalized);