summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
diff options
context:
space:
mode:
authorAlex Pott2016-05-31 00:44:39 +0100
committerAlex Pott2016-05-31 00:44:39 +0100
commit6749853b33cfa48e2e4828db95bce118a16cc463 (patch)
tree18248f5123e40ee2589c308e252a5d38cd757f6f /core/modules/rest/src/Plugin/rest/resource/EntityResource.php
parent95481848dc63f6c512d79f68f753484c153373dc (diff)
Issue #2631774 by Wim Leers, marthinal, dawehner, tedbow, tyler.frankenstein, gabesullice, valthebald: Impossible to update Comment entity with REST (HTTP PATCH): bundle field not allowed to be updated, but EntityNormalizer::denormalize() requires it
Diffstat (limited to 'core/modules/rest/src/Plugin/rest/resource/EntityResource.php')
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php21
1 files changed, 16 insertions, 5 deletions
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index b4e78a4..63857e4 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -146,13 +146,24 @@ class EntityResource extends ResourceBase {
}
// Overwrite the received properties.
- $langcode_key = $entity->getEntityType()->getKey('langcode');
+ $entity_keys = $entity->getEntityType()->getKeys();
foreach ($entity->_restSubmittedFields as $field_name) {
$field = $entity->get($field_name);
- // It is not possible to set the language to NULL as it is automatically
- // re-initialized. As it must not be empty, skip it if it is.
- if ($field_name == $langcode_key && $field->isEmpty()) {
- continue;
+
+ // Entity key fields need special treatment: together they uniquely
+ // identify the entity. Therefore it does not make sense to modify any of
+ // them. However, rather than throwing an error, we just ignore them as
+ // long as their specified values match their current values.
+ if (in_array($field_name, $entity_keys, TRUE)) {
+ // Unchanged values for entity keys don't need access checking.
+ if ($original_entity->get($field_name)->getValue() === $entity->get($field_name)->getValue()) {
+ continue;
+ }
+ // It is not possible to set the language to NULL as it is automatically
+ // re-initialized. As it must not be empty, skip it if it is.
+ elseif (isset($entity_keys['langcode']) && $field_name === $entity_keys['langcode'] && $field->isEmpty()) {
+ continue;
+ }
}
if (!$original_entity->get($field_name)->access('edit')) {