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

Code

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];
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.