Commit 9b650e91 authored by catch's avatar catch
Browse files

Issue #2730497 by dawehner: REST Views override existing REST routes

parent aa6235fb
......@@ -237,8 +237,8 @@ public function alterRoutes(RouteCollection $collection) {
$route_path = RouteCompiler::getPathWithoutDefaults($route);
$route_path = RouteCompiler::getPatternOutline($route_path);
// Ensure that we don't override a route which is already controlled by
// views.
if (!$route->hasDefault('view_id') && ('/' . $view_path == $route_path)) {
// views. Also ensure that we don't override for example REST routes.
if (!$route->hasDefault('view_id') && ('/' . $view_path == $route_path) && (!$route->getMethods() || in_array('GET', $route->getMethods()))) {
$parameters = $route->compile()->getPathVariables();
// @todo Figure out whether we need to merge some settings (like
......
......@@ -260,6 +260,44 @@ public function testAlterRoute() {
$this->assertSame($collection->get('test_route_2'), $route_2);
}
/**
* Tests the altering of a REST route.
*/
public function testAlterRestRoute() {
$collection = new RouteCollection();
$route = new Route('test_route', ['_controller' => 'Drupal\Tests\Core\Controller\TestController::content']);
$route->setMethods(['POST']);
$collection->add('test_route', $route);
list($view) = $this->setupViewExecutableAccessPlugin();
$display = [];
$display['display_plugin'] = 'page';
$display['id'] = 'page_1';
$display['display_options'] = [
'path' => 'test_route',
];
$this->pathPlugin->initDisplay($view, $display);
$this->pathPlugin->collectRoutes($collection);
$view_route_names = $this->pathPlugin->alterRoutes($collection);
$this->assertEquals([], $view_route_names);
// Ensure that the test_route is not overridden.
$this->assertCount(2, $collection);
$route = $collection->get('test_route');
$this->assertTrue($route instanceof Route);
$this->assertFalse($route->hasDefault('view_id'));
$this->assertFalse($route->hasDefault('display_id'));
$this->assertSame($collection->get('test_route'), $route);
$route = $collection->get('view.test_id.page_1');
$this->assertTrue($route instanceof Route);
$this->assertEquals('test_id', $route->getDefault('view_id'));
$this->assertEquals('page_1', $route->getDefault('display_id'));
$this->assertEquals('my views title', $route->getDefault('_title'));
}
/**
* Tests the alter route method with preexisting title callback.
*/
......
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