menu_set_active_item

5 menu.inc menu_set_active_item($path = NULL)
6 menu.inc menu_set_active_item($path)
7 menu.inc menu_set_active_item($path)
8 menu.inc menu_set_active_item($path)

Set the active path, which determines which page is loaded.

Note that this may not have the desired effect unless invoked very early in the page load, such as during hook_boot, or unless you call menu_execute_active_handler() to generate your page output.

Parameters

$path: A Drupal path - not a path alias.

Related topics

2 calls to menu_set_active_item()

File

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

Code

function menu_set_active_item($path) {
  $_GET['q'] = $path;
  // Since the active item has changed, the active menu trail may also be out
  // of date.
  drupal_static_reset('menu_set_active_trail');
}

Comments

Function not available in hook_boot

The parameters section suggests invoking the menu_set_active_item() function during hook_boot(), but this leads to an 'undefined function' error in my module. Is there another hook that can invoke menu_set_active_item() or drupal_access_denied() early on in the page load?

Specifically, I'm trying to layer on an additional, external security mechanism (fed from a non-Drupal cookie), and I want to be able to deny access to pages as early on as possible.

hook_init()

I'm using this function

I'm using this function within my theme at template.php

function MYTHEME_preprocess_page(&$vars) {
if(!empty($vars['node'])){
switch ($vars['node']->type) {
case 'article':
//change MY_TRAIL for your Drupal path (can be aliased, don't need full path)
menu_set_active_item('MY_TRAIL'');
break;
case 'page':
menu_set_active_item('pages/index');
break;
}
}

Login or register to post comments