From 03f4982c6c7e0bee67fab08639405f938c832e13 Mon Sep 17 00:00:00 2001 From: Dries <dries@buytaert.net> Date: Wed, 18 Dec 2013 14:46:06 -0500 Subject: [PATCH] Issue #2138667 by dawehner: Allow to specify the route name for a path-based view. --- .../config/schema/views.display.schema.yml | 3 +++ .../Plugin/views/display/PathPluginBase.php | 8 +++++-- .../Plugin/display/PathPluginBaseTest.php | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/modules/views/config/schema/views.display.schema.yml b/core/modules/views/config/schema/views.display.schema.yml index f7279bec6c87..601c22940cda 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 01790c270a55..1879e13aacb4 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 0f5289f9a5e8..37abd60ba5f1 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')); } /** -- GitLab