Definition

menu_execute_active_handler()
drupal-5/includes/menu.inc, line 385

Description

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

Namesort iconDescription
Menu systemDefine the navigation menus, and route page requests to code based on URLs.

Code

<?php
function menu_execute_active_handler() {
  if (_menu_site_is_offline()) {
    return MENU_SITE_OFFLINE;
  }

  $menu = menu_get_menu();

  // Determine the menu item containing the callback.
  $path = $_GET['q'];
  while ($path && !isset($menu['callbacks'][$path])) {
    $path = substr($path, 0, strrpos($path, '/'));
  }

  if ($path === '' || !isset($menu['callbacks'][$path])) {
    return MENU_NOT_FOUND;
  }

  if (!function_exists($menu['callbacks'][$path]['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['callbacks'][$path]['callback arguments']) ? $menu['callbacks'][$path]['callback arguments'] : array();
  $arg = substr($_GET['q'], strlen($path) + 1);
  if (strlen($arg)) {
    $arguments = array_merge($arguments, explode('/', $arg));
  }

  return call_user_func_array($menu['callbacks'][$path]['callback'], $arguments);
}
?>