Commit 03f4982c authored by Dries's avatar Dries

Issue #2138667 by dawehner: Allow to specify the route name for a path-based view.

parent ebad0cd9
......@@ -11,6 +11,9 @@ views.display.page:
path:
type: string
label: 'Page path'
route_name:
type: string
label: 'Route name'
menu:
type: mapping
label: 'Menu'
......
......@@ -109,6 +109,7 @@ protected function isDefaultTabPath() {
protected function defineOptions() {
$options = parent::defineOptions();
$options['path'] = array('default' => '');
$options['route_name'] = array('default' => '');
return $options;
}
......@@ -197,8 +198,11 @@ public function collectRoutes(RouteCollection $collection) {
$route = $this->getRoute($view_id, $display_id);
$collection->add("view.$view_id.$display_id", $route);
return array("$view_id.$display_id" => "view.$view_id.$display_id");
if (!($route_name = $this->getOption('route_name'))) {
$route_name = "view.$view_id.$display_id";
}
$collection->add($route_name, $route);
return array("$view_id.$display_id" => $route_name);
}
/**
......
......@@ -116,7 +116,31 @@ public function testCollectRoutes() {
$this->assertTrue($route instanceof Route);
$this->assertEquals('test_id', $route->getDefault('view_id'));
$this->assertEquals('page_1', $route->getDefault('display_id'));
}
/**
* Tests the collect routes method with an alternative route name in the UI.
*/
public function testCollectRoutesWithSpecialRouteName() {
list($view) = $this->setupViewExecutableAccessPlugin();
$display = array();
$display['display_plugin'] = 'page';
$display['id'] = 'page_1';
$display['display_options'] = array(
'path' => 'test_route',
'route_name' => 'test_route',
);
$this->pathPlugin->initDisplay($view, $display);
$collection = new RouteCollection();
$result = $this->pathPlugin->collectRoutes($collection);
$this->assertEquals(array('test_id.page_1' => 'test_route'), $result);
$route = $collection->get('test_route');
$this->assertTrue($route instanceof Route);
$this->assertEquals('test_id', $route->getDefault('view_id'));
$this->assertEquals('page_1', $route->getDefault('display_id'));
}
/**
......
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