From 52da1905b4c970fb3e6fc5ada4e2fc08ddf82945 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 18 Apr 2014 21:14:18 +0100 Subject: [PATCH] Issue #2227555 by dawehner: Use route options instead of route defaults for view_argument_map. --- .../views/Plugin/views/display/PathPluginBase.php | 4 ++-- .../lib/Drupal/views/Routing/ViewPageController.php | 3 ++- .../Tests/Plugin/display/PathPluginBaseTest.php | 4 ++-- .../views/Tests/Routing/ViewPageControllerTest.php | 12 ++++++++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php index 3737a36eaabb..bf4e008c3916 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php @@ -197,7 +197,7 @@ protected function getRoute($view_id, $display_id) { $route->setOption('_access_mode', 'ANY'); // Set the argument map, in order to support named parameters. - $route->setDefault('_view_argument_map', $argument_map); + $route->setOption('_view_argument_map', $argument_map); return $route; } @@ -253,7 +253,7 @@ public function alterRoutes(RouteCollection $collection) { $argument_map['arg_' . $position] = $parameter_name; } // Set the corrected path and the mapping to the route object. - $route->setDefault('_view_argument_map', $argument_map); + $route->setOption('_view_argument_map', $argument_map); $route->setPath($path); $collection->add($name, $route); diff --git a/core/modules/views/lib/Drupal/views/Routing/ViewPageController.php b/core/modules/views/lib/Drupal/views/Routing/ViewPageController.php index 3e348915d25d..1898b0384f65 100644 --- a/core/modules/views/lib/Drupal/views/Routing/ViewPageController.php +++ b/core/modules/views/lib/Drupal/views/Routing/ViewPageController.php @@ -11,6 +11,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\views\ViewExecutableFactory; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -74,7 +75,7 @@ public function handle(Request $request) { $view->initHandlers(); $args = array(); - $map = $request->attributes->get('_view_argument_map', array()); + $map = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)->getOption('_view_argument_map', array()); $arguments_length = count($view->argument); for ($argument_index = 0; $argument_index < $arguments_length; $argument_index++) { // Allow parameters be pulled from the request. diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php index 81f8307ed1bc..95f140ebfe8c 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php @@ -210,7 +210,7 @@ public function testCollectRoutesWithNamedParameters() { $this->assertEquals('/test_route/{node}/example', $route->getPath()); $this->assertEquals('test_id', $route->getDefault('view_id')); $this->assertEquals('page_1', $route->getDefault('display_id')); - $this->assertEquals(array('arg_0' => 'node'), $route->getDefault('_view_argument_map')); + $this->assertEquals(array('arg_0' => 'node'), $route->getOption('_view_argument_map')); } /** @@ -246,7 +246,7 @@ public function testAlterRoutesWithParameters() { $this->assertEquals('page_1', $route->getDefault('display_id')); // Ensure that the path did not changed and placeholders are respected. $this->assertEquals('/test_route/{parameter}', $route->getPath()); - $this->assertEquals(array('arg_0' => 'parameter'), $route->getDefault('_view_argument_map')); + $this->assertEquals(array('arg_0' => 'parameter'), $route->getOption('_view_argument_map')); } /** diff --git a/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php b/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php index 4a52eac3135d..94ce9a7eef94 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php @@ -9,9 +9,11 @@ use Drupal\Tests\UnitTestCase; use Drupal\views\Routing\ViewPageController; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; +use Symfony\Component\Routing\Route; /** * Tests the page controller but not the actual execution/rendering of a view. @@ -95,6 +97,7 @@ public function testPageController() { $request = new Request(); $request->attributes->set('view_id', 'test_page_view'); $request->attributes->set('display_id', 'default'); + $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('')); $output = $this->pageController->handle($request); $this->assertInternalType('array', $output); @@ -141,6 +144,7 @@ public function testHandleWithArgumentsWithoutOverridden() { $request->attributes->set('display_id', 'page_1'); // Add the argument to the request. $request->attributes->set('arg_0', 'test-argument'); + $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('')); $this->pageController->handle($request); } @@ -187,9 +191,9 @@ public function testHandleWithArgumentsOnOveriddenRoute() { $request->attributes->set('display_id', 'page_1'); // Add the argument to the request. $request->attributes->set('parameter', 'test-argument'); - $request->attributes->set('_view_argument_map', array( + $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('', array(), array(), array('_view_argument_map' => array( 'arg_0' => 'parameter', - )); + )))); $this->pageController->handle($request); } @@ -240,9 +244,9 @@ public function testHandleWithArgumentsOnOveriddenRouteWithUpcasting() { $raw_variables = new ParameterBag(array('test_entity' => 'example_id')); $request->attributes->set('_raw_variables', $raw_variables); - $request->attributes->set('_view_argument_map', array( + $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('', array(), array(), array('_view_argument_map' => array( 'arg_0' => 'test_entity', - )); + )))); $this->pageController->handle($request); } -- GitLab