In
#2451397: Entity denormalization fails to retrieve bundle →
Drupal\serialization\Normalizer\EntityNormalizer::denormalize() had to add _restSubmittedFields to the entity object so that Drupal\rest\Plugin\rest\resource\EntityResource::post() and ::patch() could work at all.
That work-around sets a new, undefined, public-but-for-internal-use-only property on Entity objects:
$entity->_restSubmittedFields
The reason that work-around was introduced: field-level access checking must occur, but only for those fields that are being edited (POSTed or PATCHed, respectively). Doing field access checking on all fields regardless of the field data that is actually being provided in the request body would result in incorrect REST API behavior. (For example: an optional field that is not being created or updated would still be validated, and might result in a validation error. We ran into this exact problem at
#2405091: Cannot create user entities - {"error":"Access denied on creating field pass"} →
, which had a work-around added for it.)
To know which fields to check access for, i.e. the fields that were actually sent (in the request body), we need to pass information from an earlier point in the call stack to a later point in the call stack. When the entity is being denormalized (i.e. from array-of-sent-data to Entity PHP object), we know which fields are present (in that array), and we need to pass that to the REST resource plugin.
In pseudocode:
\Drupal\rest\RequestHandler::handle($request) {
$method = $request->getMethod();
$entity_data = $serializer->decode($request->getBody())
// In here we must set $entity->_restSubmittedFields…
$entity = $serializer->denormalize($entity_data);
// So that the method on the plugin that we call here knows which fields were actually sent.
return $entity_rest_resource_plugin->$method($entity);
}Unfortunately, this has some negative consequences:
The root cause actually does not lie in the Serialization or REST modules. It lies in the Entity/Field/Typed Data API. Of course, the Entity/Field/Typed Data API was originally not designed with a REST API in mind. So the problem is that WSCCI did not pay the full integration cost. IOW: this is WSCCI Initiative technical debt from 2015 that we never paid off. It was rushed in because apparently in 2015, it was still impossible to POST or PATCH entities.
The capability that is missing in the Entity/Field/Typed Data API which REST functionality needs is tracking of changed aka "dirty" fields:
POST requests, we need to know the changes compared to the initial/default field valuesPATCH requests, we need to know the changes compared to the stored field values.Either:
None.
None.
None.
A summary is helpful because this issue is quite confusing:
ContentEntityBase.
changed timestamp for translatable entities when translations change. But then that was solved in a different way. Comments #7–#11.onChange() API in #22–#29.ContentEntityBase::values. But he dispels part of what @yched said.::onChange() was designed to allow for determining changes, but that it was never implemented.Postponed
11.0 🔥
rest.module
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.