menu_get_object

Versions
6 – 7
menu_get_object($type = 'node', $position = 1, $path = NULL)

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

▾ 13 functions call menu_get_object()

book_block in core/modules/book/book.module
Implementation of hook_block().
googleanalytics_footer in contrib/google_analytics/googleanalytics.module
Implementation of hook_footer() to insert Javascript at the end of the page.
i18ncontent_help in contrib/i18n/i18ncontent/i18ncontent.module
Implementation of hook_help().
i18n_textfield_process in contrib/i18n/i18n.module
Process callback for textfield elements.
lightbox2_preprocess_page in contrib/lightbox2/lightbox2.module
node_nodewords_type_id in contrib/nodewords/includes/node.inc
Implements hook_nodewords_type_id().
og_determine_context in contrib/og/og.module
Set group context using the menu system.
page_title_get_title in contrib/page_title/page_title.module
Simple wrapper function to get the currently set title for a page
page_title_page_get_title in contrib/page_title/page_title.module
Determines what title should be sent to the page template.
template_preprocess_page in core/includes/theme.inc
Process variables for page.tpl.php
_i18n_get_context_lang in contrib/i18n/i18n.module
Get language from context.
_i18n_init_mode in contrib/i18n/i18n.module
Initialize selection mode
_uc_catalog_navigation in contrib/ubercart/uc_catalog/uc_catalog.module
Emulate Drupal's menu system, but based soley on the structure of "Product Catalog".

Code

core/includes/menu.inc, line 699

<?php
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];
  }
}
?>