Same name and namespace in other branches
  1. 4.7.x includes/menu.inc \menu_set_active_item()
  2. 5.x includes/menu.inc \menu_set_active_item()
  3. 6.x includes/menu.inc \menu_set_active_item()
  4. 7.x 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 367
API for the Drupal menu system.

Code

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

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