function menu_get_object in Drupal 6
Same name and namespace in other branches
- 7 includes/menu.inc \menu_get_object()
Get a loaded object from a router item.
menu_get_object() will provide you the current node on paths like node/5, node/5/revisions/48 etc. menu_get_object('user') will give you the user account on user/5 etc. Note - this function should never be called within a _to_arg function (like user_current_to_arg()) since this may result in an infinite recursion.
Parameters
$type: Type of the object. These appear in hook_menu definitons as %type. Core provides aggregator_feed, aggregator_category, contact, filter_format, forum_term, menu, menu_link, node, taxonomy_vocabulary, user. See the relevant {$type}_load function for more on each. Defaults to node.
$position: The expected position for $type object. For node/%node this is 1, for comment/reply/%node this is 2. Defaults to 1.
$path: See menu_get_item() for more on this. Defaults to the current path.
Related topics
2 calls to menu_get_object()
- book_block in modules/
book/ book.module - Implementation of hook_block().
- template_preprocess_page in includes/
theme.inc - Process variables for page.tpl.php
File
- includes/
menu.inc, line 702 - API for the Drupal menu system.
Code
function menu_get_object($type = 'node', $position = 1, $path = NULL) {
$router_item = menu_get_item($path);
if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type . '_load') {
return $router_item['map'][$position];
}
}