diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php index c47a72c..751de28 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php @@ -66,6 +66,18 @@ public function normalize($entity, $format = NULL, array $context = array()) { /** * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize(). * + * @param array $data + * Entity data to restore. + * @param string $class + * Unused, entity_create() is used to instantiate entity objects. + * @param string $format + * Format the given data was extracted from. + * @param array $context + * Options available to the denormalizer. Keys that can be used: + * - request_method: if set to "patch" the denormalization will clear out + * all default values for entity fields before applying $data to the + * entity. + * * @throws \Symfony\Component\Serializer\Exception\UnexpectedValueException */ public function denormalize($data, $class, $format = NULL, array $context = array()) { diff --git a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php index eca41bc..641d541 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php @@ -65,8 +65,18 @@ public function testPatchUpdate() { $entity = entity_load($entity_type, $entity->id(), TRUE); $this->assertEqual($entity->field_test_text->value, $patch_entity->field_test_text->value, 'Field was successfully updated.'); - // Try to empty a field. + // Make sure that the field does not get deleted if it is not present in the + // PATCH request. $normalized = $serializer->normalize($patch_entity, $this->defaultFormat); + unset($normalized['field_test_text']); + $serialized = $serializer->encode($normalized, $this->defaultFormat); + $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PATCH', $serialized, $this->defaultMimeType); + $this->assertResponse(204); + + $entity = entity_load($entity_type, $entity->id(), TRUE); + $this->assertNotNull($entity->field_test_text->value. 'Test field has not been deleted.'); + + // Try to empty a field. $normalized['field_test_text'] = array(); $serialized = $serializer->encode($normalized, $this->defaultFormat);