Commit 52da1905 authored by alexpott's avatar alexpott

Issue #2227555 by dawehner: Use route options instead of route defaults for view_argument_map.

parent b390475f
......@@ -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);
......
......@@ -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.
......
......@@ -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'));
}
/**
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment