Commit 0caaba90 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2829074 by ndrake86, borisson_, sukanya.ramakrishnan, vaibhavjain:...

Issue #2829074 by ndrake86, borisson_, sukanya.ramakrishnan, vaibhavjain: QueryString processor doesn't work for views that use contextural filters
parent dbc47502
......@@ -129,6 +129,12 @@ class QueryString extends UrlProcessorPluginBase {
}
$result_get_params->set($this->filterKey, array_values($filter_params));
// Grab any route params from the original request.
$routeParameters = Url::createFromRequest($this->request)
->getRouteParameters();
if (!empty($routeParameters)) {
$url->setRouteParameters($routeParameters);
}
$new_url = clone $url;
if ($result_get_params->all() !== [$this->filterKey => []]) {
......
......@@ -262,6 +262,41 @@ class QueryStringTest extends UnitTestCase {
}
}
/**
* Tests that contextual filter get's re-added.
*/
public function testContextualFilters() {
// Override router.
$router = $this->getMockBuilder('Drupal\Tests\Core\Routing\TestRouterInterface')
->disableOriginalConstructor()
->getMock();
$router->expects($this->any())
->method('matchRequest')
->willReturn([
'_raw_variables' => new ParameterBag(['node' => '1']),
'_route' => 'node_view',
]);
// Get the container from the setUp method and change it with the
// implementation created here, that has the route parameters.
$container = \Drupal::getContainer();
$container->set('router.no_access_checks', $router);
\Drupal::setContainer($container);
// Create facet.
$facet = new Facet([], 'facets_facet');
$facet->setFieldIdentifier('test');
$facet->setUrlAlias('test');
$facet->setFacetSourceId('facet_source__dummy');
$this->processor = new QueryString(['facet' => $facet], 'query_string', [], new Request());
$results = $this->processor->buildUrls($facet, $this->originalResults);
foreach ($results as $result) {
$this->assertEquals(['node' => 1], $result->getUrl()->getRouteParameters());
}
}
/**
* Sets up a container.
*/
......
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