menu_set_active_item

Versions
4.6 – 5
menu_set_active_item($path = NULL)
6 – 7
menu_set_active_item($path)

Sets the path of the active menu item.

Related topics

▾ 4 functions call 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.

Code

includes/menu.inc, line 367

<?php
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;
}
?>
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.