Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
52da1905
Commit
52da1905
authored
Apr 18, 2014
by
Alex Pott
Browse files
Issue
#2227555
by dawehner: Use route options instead of route defaults for view_argument_map.
parent
b390475f
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
View file @
52da1905
...
...
@@ -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
->
set
Default
(
'_view_argument_map'
,
$argument_map
);
$route
->
set
Option
(
'_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
->
set
Default
(
'_view_argument_map'
,
$argument_map
);
$route
->
set
Option
(
'_view_argument_map'
,
$argument_map
);
$route
->
setPath
(
$path
);
$collection
->
add
(
$name
,
$route
);
...
...
core/modules/views/lib/Drupal/views/Routing/ViewPageController.php
View file @
52da1905
...
...
@@ -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.
...
...
core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php
View file @
52da1905
...
...
@@ -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
->
get
Default
(
'_view_argument_map'
));
$this
->
assertEquals
(
array
(
'arg_0'
=>
'node'
),
$route
->
get
Option
(
'_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
->
get
Default
(
'_view_argument_map'
));
$this
->
assertEquals
(
array
(
'arg_0'
=>
'parameter'
),
$route
->
get
Option
(
'_view_argument_map'
));
}
/**
...
...
core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php
View file @
52da1905
...
...
@@ -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
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment