core/modules/rest/src/RequestHandler.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 8442682..ca8318e 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -162,8 +162,12 @@ protected function getArgumentResolver(RouteMatchInterface $route_match, $unseri $route_arguments = $route_match->getParameters()->all(); $upcasted_route_arguments = $route_arguments; - // Just set the values, if they are actually defined, otherwise, the - // argument resolver believe + // \Drupal\rest\Plugin\ResourceInterface plugins historically receive the + // unserialized request body as the N+1th method argument, where N is the + // number of route parameters specified on the accompanying route. To be + // able to use the argument resolver, which is not based on position but on + // name and typehint, specify commonly used names here. 0 or 1 of these will + // be used. if (isset($unserialized)) { $upcasted_route_arguments['entity'] = $unserialized; $upcasted_route_arguments['data'] = $unserialized; @@ -172,8 +176,8 @@ protected function getArgumentResolver(RouteMatchInterface $route_match, $unseri // In the case of GET the entity is stored in $upcasted_route_arguments in // the $entity_type_id key, not as 'entity', which - // \Drupal\rest\Plugin\rest\resource\EntityResource expects as their name. - if (empty($upcasted_route_arguments['entity'])) { + // \Drupal\rest\Plugin\rest\resource\EntityResource::get() expects as their name. + if (!in_array($request->getMethod(), ['PATCH', 'POST'], TRUE) && empty($upcasted_route_arguments['entity'])) { // Try to find a parameter which is an entity. foreach ($route_arguments as $value) { if ($value instanceof EntityInterface) { @@ -182,7 +186,7 @@ protected function getArgumentResolver(RouteMatchInterface $route_match, $unseri } } - if (empty($upcasted_route_arguments['original_entity'])) { + if (in_array($request->getMethod(), ['PATCH', 'POST'], TRUE) && empty($upcasted_route_arguments['original_entity'])) { // Try to find a parameter which is an entity. foreach ($route_arguments as $value) { if ($value instanceof EntityInterface) { @@ -198,7 +202,9 @@ protected function getArgumentResolver(RouteMatchInterface $route_match, $unseri if (isset($request)) { $wildcard_arguments[] = $request; } - $wildcard_arguments[] = $unserialized; + if (isset($unserialized)) { + $wildcard_arguments[] = $unserialized; + } return new ArgumentsResolver($raw_route_arguments, $upcasted_route_arguments, $wildcard_arguments); }