diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 1059bd4..f4ecbbc 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -51,7 +51,7 @@ public function get(EntityInterface $entity) { } foreach ($entity as $field_name => $field) { if (!$field->access('view')) { - unset($entity->{$field_name}); + $entity->set($field_name, NULL); } } return new ResourceResponse($entity); diff --git a/core/modules/rest/src/Tests/CreateTest.php b/core/modules/rest/src/Tests/CreateTest.php index d125f1b..110ed5b 100644 --- a/core/modules/rest/src/Tests/CreateTest.php +++ b/core/modules/rest/src/Tests/CreateTest.php @@ -191,8 +191,8 @@ public function testCreateNode() { } else { // Changed and revision_timestamp fields can never be added. - unset($entity->changed); - unset($entity->revision_timestamp); + $entity->set('changed', NULL); + $entity->set('revision_timestamp', NULL); } $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]); @@ -244,7 +244,7 @@ public function testCreateUser() { } // Changed field can never be added. - unset($entity->changed); + $entity->set('changed', NULL); $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]); diff --git a/core/modules/rest/src/Tests/UpdateTest.php b/core/modules/rest/src/Tests/UpdateTest.php index 6046ce9..896b220 100644 --- a/core/modules/rest/src/Tests/UpdateTest.php +++ b/core/modules/rest/src/Tests/UpdateTest.php @@ -53,7 +53,7 @@ public function testPatchUpdate() { )); $patch_entity = entity_create($entity_type, $patch_values); // We don't want to overwrite the UUID. - unset($patch_entity->uuid); + $patch_entity->set('uuid', NULL); $serialized = $serializer->serialize($patch_entity, $this->defaultFormat, $context); // Update the entity over the REST API.