menu_execute_active_handler

Versions
4.6 – 5
menu_execute_active_handler()
6
menu_execute_active_handler($path = NULL)
7
menu_execute_active_handler($path = NULL, $deliver = TRUE)

Execute the handler associated with the active menu item.

This is called early in the page request. The active menu item is at this point determined exclusively by the URL. The handler that is called here may, as a side effect, change the active menu item so that later menu functions (that display the menus and breadcrumbs, for example) act as if the user were in a different location on the site.

Related topics

▾ 2 functions call menu_execute_active_handler()

drupal_access_denied in includes/common.inc
Generates a 403 error if the request is not allowed.
drupal_not_found in includes/common.inc
Generates a 404 error if the request can not be handled.

Code

includes/menu.inc, line 325

<?php
function menu_execute_active_handler() {
  $menu = menu_get_menu();

  // Determine the menu item containing the callback.
  $path = $_GET['q'];
  while ($path && (!array_key_exists($path, $menu['path index']) || empty($menu['items'][$menu['path index'][$path]]['callback']))) {
    $path = substr($path, 0, strrpos($path, '/'));
  }
  if (!array_key_exists($path, $menu['path index'])) {
    return MENU_NOT_FOUND;
  }
  $mid = $menu['path index'][$path];

  if (empty($menu['items'][$mid]['callback'])) {
    return MENU_NOT_FOUND;
  }

  if (!_menu_item_is_accessible(menu_get_active_item())) {
    return MENU_ACCESS_DENIED;
  }

  // We found one, and are allowed to execute it.
  $arguments = isset($menu['items'][$mid]['callback arguments']) ? $menu['items'][$mid]['callback arguments'] : array();
  $arg = substr($_GET['q'], strlen($menu['items'][$mid]['path']) + 1);
  if (strlen($arg)) {
    $arguments = array_merge($arguments, explode('/', $arg));
  }

  call_user_func_array($menu['items'][$mid]['callback'], $arguments);
  return MENU_FOUND;
}
?>
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.