core/includes/menu.inc | 17 ++++++++++++++++- .../lib/Drupal/system/Tests/Menu/RouterTest.php | 9 +++++++++ .../tests/modules/menu_test/menu_test.module | 22 +++++++++++++++++++--- 5 Dateien geändert, 50 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-) diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 6492b10..346a8b9 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -531,7 +531,22 @@ function _menu_load_objects(&$item, &$map) { $args[$i] = &$map; } if (is_int($arg)) { - $args[$i] = isset($path_map[$arg]) ? $path_map[$arg] : ''; + // If we loaded the specified $arg index in already, supply the + // loaded argument. This is the case when e.g. two dynamic + // placeholders appear within a single router path, and the + // 'load arguments' specify the integer index of the first + // argument, in order to pass the loaded argument to the second + // argument loader. + if (isset($map[$arg])) { + $args[$i] = $map[$arg]; + } + // Otherwise, supply the string argument, if any. + elseif (isset($path_map[$arg])) { + $args[$i] = $path_map[$arg]; + } + else { + $args[$i] = ''; + } } } array_unshift($args, $value); diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php index 179ea93..0597e5f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php @@ -575,4 +575,13 @@ function testMenuLoadArgumentsInheritance() { $this->assertIdentical(unserialize($router_item['load_functions']), $load_functions, format_string('Expected load functions for router %router_path' , array('%router_path' => $router_path))); } } + + /** + * Tests that objects are passed to menu loaders when available. + */ + public function testMenuLoadArgumentObjects() { + $this->drupalGet('menu-test/load-argument-object/first/second'); + // @see menu_test_other_argument_load() + $this->assertText('Object correctly passed to menu loader.'); + } } diff --git a/core/modules/system/tests/modules/menu_test/menu_test.info b/core/modules/system/tests/modules/menu_test/menu_test.info index e31a3eb..fa93348 100644 --- a/core/modules/system/tests/modules/menu_test/menu_test.info +++ b/core/modules/system/tests/modules/menu_test/menu_test.info @@ -3,5 +3,5 @@ description = "Support module for menu hook testing." package = Testing version = VERSION core = 8.x -hidden = TRUE +;hidden = TRUE dependencies[] = test_page_test diff --git a/core/modules/system/tests/modules/menu_test/menu_test.module b/core/modules/system/tests/modules/menu_test/menu_test.module index 36cef57..019179e 100644 --- a/core/modules/system/tests/modules/menu_test/menu_test.module +++ b/core/modules/system/tests/modules/menu_test/menu_test.module @@ -363,6 +363,18 @@ function menu_test_menu() { 'access callback' => TRUE, ); + // Test that, when using two menu loaders, and the load arguments reference + // the first one, the second load function gets the loaded object passed + // instead of the integer index. + // @todo This router cannot be in the menu-test/arguments namespace because + // that would already be matched by the routers above. + $items['menu-test/load-argument-object/%menu_test_argument/%menu_test_other_argument'] = array( + 'title' => 'An item with menu load arguments that are objects', + 'load arguments' => array(2), + 'page callback' => 'menu_test_callback', + 'access callback' => TRUE, + ); + return $items; } @@ -370,14 +382,18 @@ function menu_test_menu() { * Dummy argument loader for hook_menu() to point to. */ function menu_test_argument_load($arg1) { - return FALSE; + return (object) array('foo' => 'bar'); } /** * Dummy argument loader for hook_menu() to point to. */ -function menu_test_other_argument_load($arg1) { - return FALSE; +function menu_test_other_argument_load($arg1, $arg2 = NULL) { + if (is_object($arg2) && ($arg2->foo == 'bar')) { + // @todo drupal_set_message() does not work here. + debug('Object correctly passed to menu loader.'); + } + return $arg1; } /**