diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index aa9f3b8993..ee3667c853 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -172,25 +172,26 @@ protected function createArgumentResolver(RouteMatchInterface $route_match, $uns // not based on position but on name and typehint, specify commonly used // names here. Similarly, those methods receive the original stored object // as the first method argument. + + $route_arguments_entity = NULL; + // Try to find a parameter which is an entity. + foreach ($route_arguments as $value) { + if ($value instanceof EntityInterface) { + $route_arguments_entity = $value; + break; + } + } + + if (in_array($request->getMethod(), ['PATCH', 'POST'], TRUE)) { $upcasted_route_arguments['entity'] = $unserialized; $upcasted_route_arguments['data'] = $unserialized; $upcasted_route_arguments['unserialized'] = $unserialized; - // Try to find a parameter which is an entity. - foreach ($route_arguments as $value) { - if ($value instanceof EntityInterface) { - $upcasted_route_arguments['original_entity'] = $value; - } - } + $upcasted_route_arguments['original_entity'] = $route_arguments_entity; } else { - // Try to find a parameter which is an entity. - foreach ($route_arguments as $value) { - if ($value instanceof EntityInterface) { - $upcasted_route_arguments['entity'] = $value; - } - } + $upcasted_route_arguments['entity'] = $route_arguments_entity; } // Parameters which are not defined on the route object, but still are @@ -217,7 +218,7 @@ protected function createArgumentResolver(RouteMatchInterface $route_match, $uns * @param \Symfony\Component\HttpFoundation\Request $request * The request. * - * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Use the + * @deprecated in Drupal 8.4.0, will be removed before Drupal 9.0.0. Use the * argument resolver method instead, see ::createArgumentResolver(). * * @return array