core/modules/rest/src/Plugin/rest/resource/EntityResource.php | 6 ++---- core/modules/rest/src/Tests/UpdateTest.php | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index be66ee8..2666eed 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -219,15 +219,13 @@ public function patch(EntityInterface $original_entity, EntityInterface $entity if (isset($entity_keys['langcode']) && $field_name === $entity_keys['langcode'] && $field->isEmpty()) { continue; } - // Allow sending read-only fields, as long as their value is unchanged. - if ($entity instanceof ContentEntityInterface + elseif ($entity instanceof ContentEntityInterface && $field->getFieldDefinition()->isReadOnly() && $original_entity->get($field_name)->getValue() === $entity->get($field_name)->getValue()) { continue; } - - if (!$original_entity->get($field_name)->access('edit')) { + elseif (!$original_entity->get($field_name)->access('edit')) { throw new AccessDeniedHttpException("Access denied on updating field '$field_name'."); } $original_entity->set($field_name, $field->getValue()); diff --git a/core/modules/rest/src/Tests/UpdateTest.php b/core/modules/rest/src/Tests/UpdateTest.php index 727324f..cdef82c 100644 --- a/core/modules/rest/src/Tests/UpdateTest.php +++ b/core/modules/rest/src/Tests/UpdateTest.php @@ -283,7 +283,6 @@ public function testUpdateComment() { $entity_values['uid'] = $account->id(); $comment = Comment::create($entity_values); $comment->save(); - $comment_id = $comment->id(); $this->pass('Test case 1: PATCH comment using HAL+JSON.'); $comment->setSubject('Initial subject')->save(); @@ -301,7 +300,7 @@ public function testUpdateComment() { $this->assertNotEqual('Updated subject', $comment->getSubject()); $comment->setSubject('Updated subject'); $this->patchEntity($comment, $read_only_fields, $account, 'hal_json', 'application/hal+json'); - $comment = Comment::load($comment_id); + $comment = Comment::load($comment->id()); $this->assertEqual('Updated subject', $comment->getSubject()); $this->pass('Test case 1: PATCH comment using JSON.');