diff --git a/core/lib/Drupal/Core/Controller/ControllerResolver.php b/core/lib/Drupal/Core/Controller/ControllerResolver.php index d5193e7..febffd9 100644 --- a/core/lib/Drupal/Core/Controller/ControllerResolver.php +++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php @@ -138,11 +138,15 @@ protected function createController($controller) { */ protected function doGetArguments(Request $request, $controller, array $parameters) { $attributes = $request->attributes->all(); + $raw_parameters = $request->attributes->has('_raw_variables') ? $request->attributes->get('_raw_variables') : []; $arguments = array(); foreach ($parameters as $param) { if (array_key_exists($param->name, $attributes)) { $arguments[] = $attributes[$param->name]; } + elseif (array_key_exists($param->name, $raw_parameters)) { + $arguments[] = $attributes[$param->name]; + } elseif ($param->getClass() && $param->getClass()->isInstance($request)) { $arguments[] = $request; } @@ -166,21 +170,6 @@ protected function doGetArguments(Request $request, $controller, array $paramete throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).', $repr, $param->name)); } } - - // The parameter converter overrides the raw request attributes with the - // upcasted objects. However, it keeps a backup copy of the original, raw - // values in a special request attribute ('_raw_variables'). If a controller - // argument has a type hint, we pass it the upcasted object, otherwise we - // pass it the original, raw value. - if ($request->attributes->has('_raw_variables') && $raw = $request->attributes->get('_raw_variables')->all()) { - foreach ($parameters as $parameter) { - // Use the raw value if a parameter has no typehint. - if (!$parameter->getClass() && isset($raw[$parameter->name])) { - $position = $parameter->getPosition(); - $arguments[$position] = $raw[$parameter->name]; - } - } - } return $arguments; } diff --git a/core/modules/config_translation/src/ConfigNamesMapper.php b/core/modules/config_translation/src/ConfigNamesMapper.php index cd06c49..d232003 100644 --- a/core/modules/config_translation/src/ConfigNamesMapper.php +++ b/core/modules/config_translation/src/ConfigNamesMapper.php @@ -362,7 +362,7 @@ public function getWeight() { */ public function populateFromRequest(Request $request) { $route_match = RouteMatch::createFromRequest($request); - $this->langcode = $route_match->getParameter('langcode'); + $this->langcode = $route_match->getParameter('langcode') ?: $request->attributes->get('langcode'); } /** diff --git a/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php b/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php index 9904125..1b96b3d 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Provides a test form object. @@ -34,11 +35,11 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, $custom_attributes = NULL) { + public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $custom_attributes = NULL) { $form['element'] = array('#markup' => 'The FormTestControllerObject::buildForm() method was used for this form.'); $form['custom_attribute']['#markup'] = $custom_attributes; - $form['request_attribute']['#markup'] = $this->getRouteMatch()->getParameter('request_attribute'); + $form['request_attribute']['#markup'] = $request->attributes->get('request_attribute'); $form['bananas'] = array( '#type' => 'textfield', diff --git a/core/modules/system/tests/modules/paramconverter_test/src/TestControllers.php b/core/modules/system/tests/modules/paramconverter_test/src/TestControllers.php index 1ebee52..482eb0d 100644 --- a/core/modules/system/tests/modules/paramconverter_test/src/TestControllers.php +++ b/core/modules/system/tests/modules/paramconverter_test/src/TestControllers.php @@ -8,6 +8,7 @@ namespace Drupal\paramconverter_test; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Routing\RouteMatch; use Drupal\node\NodeInterface; use Symfony\Component\HttpFoundation\Request; diff --git a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php index 91491c8..d015a31 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php @@ -74,8 +74,8 @@ public function testGetArguments() { )); $arguments = $this->controllerResolver->getArguments($request, $controller); - $this->assertEquals($mock_entity, $arguments[0], 'Type hinted variables should use upcasted values.'); - $this->assertEquals(1, $arguments[1], 'Not type hinted variables should use not upcasted values.'); + $this->assertEquals($mock_entity, $arguments[0]); + $this->assertEquals($mock_account, $arguments[1]); $this->assertEquals(RouteMatch::createFromRequest($request), $arguments[2], 'Ensure that the route match object is passed along as well'); }