Problem/Motivation
When trying to update a comment via REST using:
- method: PATCH
- URL:
/comment/1
Content-Type: application/json
{"langcode":[{"value":"en"}],"subject":[{"value":"New Subject"}],"uid":[{"target_id":"1","url":"/discasaurus.com/user/1"}],"status":[{"value":"1"}],"comment_type":[{"target_id":"comment"}],"default_langcode":[{"value":"1"}],"comment_body":[{"value":"<p>New body...</p>","format":"basic_html"}]
}
A 403 response is sent, with the following body:
{"error":"Access denied on updating field 'comment_type'."}
Removing the comment_type
from the request body results in a 400 response with the following body:
{"error":"A string must be provided as a bundle value."}
Proposed resolution
In \Drupal\rest\Plugin\rest\resource\EntityResource::patch()
(for updating entities via REST), retrieve an entity type's bundle key, and ignore any fields that set it.
Once that is done, you'll get an exception like this though:
LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\rest\ResourceResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 159 of /var/www/discasaurus.com/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).
This is due to rdf_comment_storage_load()
generating a URL that causes cacheability metadata to be bubbled. So a minor change/fix to rdf_comment_storage_load()
is also necessary.
Remaining tasks
TBD
User interface changes
None.
API changes
TBD
Data model changes
TBD