function _menu_load_objects in Drupal 7
Same name and namespace in other branches
- 6 includes/menu.inc \_menu_load_objects()
Loads objects into the map as defined in the $item['load_functions'].
Parameters
$item: A menu router or menu link item
$map: An array of path arguments; for example, array('node', '5').
Return value
Returns TRUE for success, FALSE if an object cannot be loaded. Names of object loading functions are placed in $item['load_functions']. Loaded objects are placed in $map[]; keys are the same as keys in the $item['load_functions'] array. $item['access'] is set to FALSE if an object cannot be loaded.
Related topics
2 calls to _menu_load_objects()
- _menu_link_translate in includes/
menu.inc - Provides menu link access control, translation, and argument handling.
- _menu_translate in includes/
menu.inc - Handles dynamic path translation and menu access control.
File
- includes/
menu.inc, line 564 - API for the Drupal menu system.
Code
function _menu_load_objects(&$item, &$map) {
if ($load_functions = $item['load_functions']) {
// If someone calls this function twice, then unserialize will fail.
if (!is_array($load_functions)) {
$load_functions = unserialize($load_functions);
}
$path_map = $map;
foreach ($load_functions as $index => $function) {
if ($function) {
$value = isset($path_map[$index]) ? $path_map[$index] : '';
if (is_array($function)) {
// Set up arguments for the load function. These were pulled from
// 'load arguments' in the hook_menu() entry, but they need
// some processing. In this case the $function is the key to the
// load_function array, and the value is the list of arguments.
$args = current($function);
$function = key($function);
$load_functions[$index] = $function;
// Some arguments are placeholders for dynamic items to process.
foreach ($args as $i => $arg) {
if ($arg === '%index') {
// Pass on argument index to the load function, so multiple
// occurrences of the same placeholder can be identified.
$args[$i] = $index;
}
if ($arg === '%map') {
// Pass on menu map by reference. The accepting function must
// also declare this as a reference if it wants to modify
// the map.
$args[$i] =& $map;
}
if (is_int($arg)) {
$args[$i] = isset($path_map[$arg]) ? $path_map[$arg] : '';
}
}
array_unshift($args, $value);
$return = call_user_func_array($function, $args);
}
else {
$return = $function($value);
}
// If callback returned an error or there is no callback, trigger 404.
if ($return === FALSE) {
$item['access'] = FALSE;
$map = FALSE;
return FALSE;
}
$map[$index] = $return;
}
}
$item['load_functions'] = $load_functions;
}
return TRUE;
}