Commit 1242612e authored by webchick's avatar webchick

#606966 by chx, sun, mr.baileys: Fixed 'load arguments' of parent path are not inherited

parent 379ef5db
......@@ -521,8 +521,8 @@ function menu_execute_active_handler($path = NULL, $deliver = TRUE) {
function _menu_load_objects(&$item, &$map) {
if ($load_functions = $item['load_functions']) {
// If someone calls this function twice, then unserialize will fail.
if ($load_functions_unserialized = unserialize($load_functions)) {
$load_functions = $load_functions_unserialized;
if (!is_array($load_functions)) {
$load_functions = unserialize($load_functions);
}
$path_map = $map;
foreach ($load_functions as $index => $function) {
......@@ -3396,7 +3396,7 @@ function _menu_router_build($callbacks) {
$fit = (1 << $number_parts) - 1;
}
$masks[$fit] = 1;
$item['load_functions'] = empty($load_functions) ? '' : serialize($load_functions);
$item['_load_functions'] = $load_functions;
$item['to_arg_functions'] = empty($to_arg_functions) ? '' : serialize($to_arg_functions);
$item += array(
'title' => '',
......@@ -3499,6 +3499,10 @@ function _menu_router_build($callbacks) {
$item['theme arguments'] = $parent['theme arguments'];
}
}
// Same for load arguments, if the parent path defines any.
if (!isset($item['load arguments']) && !empty($parent['load arguments'])) {
$item['_load_functions'] = $parent['_load_functions'];
}
}
}
if (!isset($item['access callback']) && isset($item['access arguments'])) {
......@@ -3512,6 +3516,7 @@ function _menu_router_build($callbacks) {
$item['access callback'] = intval($item['access callback']);
}
$item['load_functions'] = empty($item['_load_functions']) ? '' : serialize($item['_load_functions']);
$item += array(
'access arguments' => array(),
'access callback' => '',
......
......@@ -464,6 +464,22 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$asserted_title = $override ? 'Alternative example title - Case ' . $case_no : 'Example title - Case ' . $case_no;
$this->assertTitle($asserted_title . ' | Drupal', t('Menu title is') . ': ' . $asserted_title, 'Menu');
}
/**
* Tests inheritance of 'load arguments'.
*/
function testMenuLoadArgumentsInheritance() {
$arg1 = $this->randomName();
$arg2 = $this->randomName();
$expected = print_r(array('%menu_test_argument' => $arg1, '%' => $arg2), TRUE);
$this->drupalGet("menu-test/arguments/$arg1/$arg2");
$this->assertRaw($expected, t('Inherited load arguments found.'));
$this->drupalGet("menu-test/arguments/$arg1/$arg2/default");
$this->assertRaw($expected, t('Inherited load arguments found.'));
$this->drupalGet("menu-test/arguments/$arg1/$arg2/task");
$this->assertRaw($expected, t('Inherited load arguments found.'));
}
}
/**
......
......@@ -255,9 +255,60 @@ function menu_test_menu() {
'page callback' => 'menu_test_callback',
);
// Load arguments inheritance test.
$items['menu-test/arguments/%menu_test_argument/%'] = array(
'title' => 'Load arguments inheritance test',
'load arguments' => array(3),
'page callback' => 'menu_test_arguments',
'page arguments' => array(2),
'access callback' => TRUE,
);
$items['menu-test/arguments/%menu_test_argument/%/default'] = array(
'title' => 'Default local task',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['menu-test/arguments/%menu_test_argument/%/task'] = array(
'title' => 'Local task',
'page callback' => 'menu_test_arguments',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Menu argument loader for the 'load arguments' inheritance test.
*
* @param $arg1
* The path argument defined as %menu_test_argument.
* @param $arg2
* The additional path argument that should be passed due to 'load arguments'.
*
* @return
* An array containing $arg1 and $arg2.
*/
function menu_test_argument_load($arg1, $arg2) {
return array('%menu_test_argument' => $arg1, '%' => $arg2);
}
/**
* Page callback for the 'load arguments' inheritance test.
*
* @param $joined_args
* An associative array containing the values for both path arguments, as
* intercepted and processed by menu_test_argument_load():
* - %menu_test_argument: The primary path argument string.
* - %: The additional argument string.
*
* @return
* A dump of the loaded %menu_test_argument argument.
*/
function menu_test_arguments($joined_args) {
return print_r($joined_args, TRUE);
}
/**
* Dummy callback for hook_menu() to point to.
*
......
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