_menu_helper_active_item_state

custom/menu_helper/menu_helper_active/menu_helper_active.module, line 69

Versions
6
_menu_helper_active_item_state($on=TRUE)

Set the active item state to use custom active path.

This function allow the menu_helper_tree_output() function to set (and unset) the active menu item before and after rendering a menu. It is very important to not completely over-write the active menu item which could be used by another module or theme.

Parameters

$on Boolean to set whether to change current path to active path or vice-versa

Return value

A boolean set to TRUE is the state was changed or FALSE if there is no active path

▾ 2 functions call _menu_helper_active_item_state()

menu_helper_active_item_state_off in custom/menu_helper/menu_helper_active/menu_helper_active.module
Restore $_GET[q] its orginal value.
menu_helper_active_item_state_on in custom/menu_helper/menu_helper_active/menu_helper_active.module
Reset $_GET[q] to custom active path.

Code

<?php
function _menu_helper_active_item_state($on=TRUE) {
  static $current_path;
  static $active_path;

  // Store both default paths
  if (!isset($current_path ) ) {
    $current_path = $_GET['q'];
  }
  if (!isset($active_path) ) {
    $active_path = _menu_helper_active_get_active_path();
  }

  // Do not change anything if there is not active path
  if (!$active_path) {
    return FALSE;
  }

  if ($on) {
    $_GET['q'] = $active_path;  // aka menu_set_active_item($active_item_path );
  }
  else {
    $_GET['q'] = $current_path;
  }

  return TRUE;

}
?>