diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php index e1efc20..84d5440 100644 --- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php @@ -81,7 +81,9 @@ public function normalize($entity, $format = NULL, array $context = array()) { if (isset($context['included_fields'])) { $fields = array(); foreach ($context['included_fields'] as $field_name) { - $fields[] = $entity->get($field_name); + if ($entity->hasField($field_name)) { + $fields[] = $entity->get($field_name); + } } } else { diff --git a/core/modules/hal/tests/src/Functional/EntityResource/EntityTest/EntityTestHalJsonRelatedTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTest/EntityTestHalJsonRelatedTest.php index c5eca2b..df1f777 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/EntityTest/EntityTestHalJsonRelatedTest.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTest/EntityTestHalJsonRelatedTest.php @@ -58,4 +58,32 @@ public function setUp() { $this->entity->save(); } + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + $normalized = parent::getExpectedNormalizedEntity(); + $normalized['_links'][$this->baseUrl . '/rest/relation/entity_test/entity_test/field_entity_test_no_label'] = [ + [ + 'href' => '', + 'lang' => 'en', + ] + ]; + $normalized['_embedded'][$this->baseUrl . '/rest/relation/entity_test/entity_test/field_entity_test_no_label'] = [ + [ + '_links' => [ + 'self' => [ + 'href' => '', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/entity_test_no_label/entity_test_no_label', + ], + ], + 'lang' => 'en', + ], + ]; + + return $normalized; + } + }