You are here

function menu_set_active_item in Drupal 5

Same name and namespace in other branches
  1. 4 includes/menu.inc \menu_set_active_item()
  2. 6 includes/menu.inc \menu_set_active_item()
  3. 7 includes/menu.inc \menu_set_active_item()

Sets the path of the active menu item.

Related topics

4 calls to menu_set_active_item()
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.
menu_get_active_item in includes/menu.inc
Returns the ID of the active menu item.
menu_set_location in includes/menu.inc
Change the current menu location of the user.

File

includes/menu.inc, line 430
API for the Drupal menu system.

Code

function menu_set_active_item($path = NULL) {
  static $stored_mid;
  if (!isset($stored_mid) || isset($path)) {
    if (!isset($path)) {
      $path = $_GET['q'];
    }
    else {
      $_GET['q'] = $path;
    }
    $menu = menu_get_menu();
    while ($path && !isset($menu['path index'][$path])) {
      $path = substr($path, 0, strrpos($path, '/'));
    }
    $stored_mid = isset($menu['path index'][$path]) ? $menu['path index'][$path] : 0;

    // Search for default local tasks to activate instead of this item.
    $continue = TRUE;
    while ($continue) {
      $continue = FALSE;
      if (isset($menu['items'][$stored_mid]['children'])) {
        foreach ($menu['items'][$stored_mid]['children'] as $cid) {
          if ($menu['items'][$cid]['type'] & MENU_LINKS_TO_PARENT) {
            $stored_mid = $cid;
            $continue = TRUE;
          }
        }
      }
    }

    // Reset the cached $menu in menu_get_item().
    menu_get_item(NULL, NULL, TRUE);
  }
  return $stored_mid;
}