.../src/Plugin/rest/resource/EntityResource.php | 1 + .../EntityResource/EntityResourceTestBase.php | 28 ++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index b356ca6..dbd9a09 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -226,6 +226,7 @@ public function patch(EntityInterface $original_entity, EntityInterface $entity } // Overwrite the received fields. + // @todo Remove $changed_fields in https://www.drupal.org/node/2906129. $changed_fields = []; foreach ($entity->_restSubmittedFields as $field_name) { $field = $entity->get($field_name); diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 07b04ef..1fc1f46 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -1092,22 +1092,20 @@ public function testPatch() { $modified_entity->get($patch_protected_field_name)->setValue($original_values[$patch_protected_field_name]); } - if ($this->entity->hasField('rest_test_validation')) { - // Change the rest_test_validation field to prove that then its validation - // does run. In subsequent test assertions, it will not be modified, and - // then should not trigger validation errors. - $modified_entity->get('rest_test_validation')->setValue('ALWAYS_FAIL'); - $valid_request_body = $this->getNormalizedPatchEntity() + $this->serializer->normalize($modified_entity, static::$format); - $request_options[RequestOptions::BODY] = $this->serializer->serialize($valid_request_body, static::$format); - $response = $this->request('PATCH', $url, $request_options); - $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nrest_test_validation: REST test validation failed\n", $response); + // Change the rest_test_validation field to prove that then its validation + // does run. In subsequent test assertions, it will not be modified, and + // then should not trigger validation errors. + $modified_entity->get('rest_test_validation')->setValue('ALWAYS_FAIL'); + $valid_request_body = $this->getNormalizedPatchEntity() + $this->serializer->normalize($modified_entity, static::$format); + $request_options[RequestOptions::BODY] = $this->serializer->serialize($valid_request_body, static::$format); + $response = $this->request('PATCH', $url, $request_options); + $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nrest_test_validation: REST test validation failed\n", $response); - // Set the rest_test_validation field to always fail validation, which - // allows asserting that not modifying that field does not trigger - // validation errors. - $this->entity->set('rest_test_validation', 'ALWAYS_FAIL'); - $this->entity->save(); - } + // Set the rest_test_validation field to always fail validation, which + // allows asserting that not modifying that field does not trigger + // validation errors. + $this->entity->set('rest_test_validation', 'ALWAYS_FAIL'); + $this->entity->save(); } // 200 for well-formed PATCH request that sends all fields (even including