From 20ec5dc16dbe134b8447186fc3a986c9d17b35a6 Mon Sep 17 00:00:00 2001 From: webchick Date: Fri, 29 Mar 2013 08:54:24 -0700 Subject: [PATCH] Issue #1945418 by tim.plunkett, jaskho: Fixed New-style placeholders in menu_router() table break breadcrumbs, menu tree, etc. --- core/includes/menu.inc | 2 ++ .../system/Tests/Menu/MenuRouterTest.php | 17 ++++++++++ .../lib/Drupal/menu_test/TestControllers.php | 31 +++++++++++++++++++ .../tests/modules/menu_test/menu_test.module | 17 ++++++++++ .../modules/menu_test/menu_test.routing.yml | 12 +++++++ 5 files changed, 79 insertions(+) create mode 100644 core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/TestControllers.php create mode 100644 core/modules/system/tests/modules/menu_test/menu_test.routing.yml diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 57681a36e59..e59615c9586 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2701,6 +2701,8 @@ function _menu_router_merge_route(array $router_item, $path) { $router_item['page callback'] = 'USES_ROUTE'; $router_item['access callback'] = TRUE; + // Translate placeholders, e.g. {foo} -> %. + $router_item['path'] = preg_replace('/{' . DRUPAL_PHP_FUNCTION_PATTERN . '}/', '%', $router_item['path']); return $router_item; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php index 7a0eb1fa6c3..d4d745106c0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php @@ -68,6 +68,23 @@ class MenuRouterTest extends WebTestBase { $this->drupalPlaceBlock('system_menu_block:menu-tools'); } + /** + * Test local tasks with route placeholders. + */ + public function testHookMenuIntegration() { + // Generate base path with random argument. + $base_path = 'foo/' . $this->randomName(8); + $this->drupalGet($base_path); + // Confirm correct controller activated. + $this->assertText('test1'); + // Confirm local task links are displayed. + $this->assertLink('Local task A'); + $this->assertLink('Local task B'); + // Confirm correct local task href. + $this->assertLinkByHref(url($base_path)); + $this->assertLinkByHref(url($base_path . '/b')); + } + /** * Test title callback set to FALSE. */ diff --git a/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/TestControllers.php b/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/TestControllers.php new file mode 100644 index 00000000000..34d42f43ee2 --- /dev/null +++ b/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/TestControllers.php @@ -0,0 +1,31 @@ + TRUE, ); + // Parent page for controller-based local tasks. + $items['foo/%'] = array( + 'title' => 'Controller-based local tasks', + 'route_name' => 'menu_router_test1', + ); + // Controller-based local task. + $items['foo/%/a'] = array( + 'title' => 'Local task A', + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + // Controller-based local task. + $items['foo/%/b'] = array( + 'title' => 'Local task B', + 'route_name' => 'menu_router_test3', + 'type' => MENU_LOCAL_TASK, + ); + return $items; } diff --git a/core/modules/system/tests/modules/menu_test/menu_test.routing.yml b/core/modules/system/tests/modules/menu_test/menu_test.routing.yml new file mode 100644 index 00000000000..9ed262c6270 --- /dev/null +++ b/core/modules/system/tests/modules/menu_test/menu_test.routing.yml @@ -0,0 +1,12 @@ +menu_router_test1: + pattern: '/foo/{bar}' + defaults: + _content: '\Drupal\menu_test\TestControllers::test1' + requirements: + _access: 'TRUE' +menu_router_test3: + pattern: '/foo/{bar}/b' + defaults: + _content: '\Drupal\menu_test\TestControllers::test2' + requirements: + _access: 'TRUE'