diff --git a/core/modules/views/config/schema/views.display.schema.yml b/core/modules/views/config/schema/views.display.schema.yml index f7279bec6c8734c8ffd8abd2a4283d5c39c09016..601c22940cda7a4ca65dbb568709fc4a18f95180 100644 --- a/core/modules/views/config/schema/views.display.schema.yml +++ b/core/modules/views/config/schema/views.display.schema.yml @@ -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' diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php index 01790c270a557758a5dc7a263b670d94716a9059..1879e13aacb4f51287cb2f9d437ac5dd5ef09024 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php @@ -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); } /** diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php index 0f5289f9a5e8cf7f21c30304ea3b0b9594eab55c..37abd60ba5f17a033d23cacfb721e572e5103d34 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php @@ -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')); } /**