You are here

function dhtml_menu_theme_menu_item in DHTML Menu 6.4

Same name and namespace in other branches
  1. 8 dhtml_menu.theme.inc \dhtml_menu_theme_menu_item()
  2. 6.3 dhtml_menu.module \dhtml_menu_theme_menu_item()

Preprocessor for menu_item. Checks whether the current item has children that were not rendered, and loads and renders them.

2 string references to 'dhtml_menu_theme_menu_item'
dhtml_menu_theme_registry_alter in ./dhtml_menu.module
Implementation of hook_theme_registry_alter(). Replaces the theme functions for the menu_item functions, and stores the original functions in order to call them when this module is done with preprocessing.
dhtml_menu_update_7101 in ./dhtml_menu.install
#7101: 7.x-1.x-dev upgrade (duplicated in 6.x-3.x). Remove two obsolete variables and rebuild all themes.

File

./dhtml_menu.theme.inc, line 54
dhtml_menu.theme.inc All functions related to generating the menu markup.

Code

function dhtml_menu_theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  global $theme;
  static $cookie = array(), $function;
  if (empty($function)) {
    $settings = variable_get('dhtml_menu_settings', array());
    if ($settings['effects']['remember'] && $settings['nav'] != 'open' && $settings['effects']['siblings'] != 'close-all') {
      $cookie = explode(',', @$_COOKIE['dhtml_menu']);
    }
    $registry = variable_get('dhtml_menu_theme', array());
    if (isset($registry[$theme]) && function_exists($registry[$theme]['menu_item'])) {
      $function = $registry[$theme]['menu_item'];
    }
    else {
      $function = 'theme_menu_item';
    }
  }

  /* When theme('menu_item') is called, the menu tree below it has been
   * rendered already. Since we are done on this recursion level,
   * one element must be popped off the stack.
   */
  $item = _dhtml_menu_stack();

  // If this item should not have DHTML, then return to the "parent" function.
  if (!$item || !empty($item['dhtml_disabled'])) {
    return $function($link, $has_children, $menu, $in_active_trail, $extra_class);
  }
  $extra_class .= ' dhtml-menu ';

  // If there are children, but they were not loaded...
  if ($has_children && !$menu) {

    // Load the tree below the current position.
    $tree = _dhtml_menu_subtree($item);

    // Render it...
    $menu = menu_tree_output($tree);

    // Sanitize the tree - uncheck has_children if no children were loaded.
    if (!$menu) {
      $has_children = FALSE;
    }
  }

  // If the current item can expand, and is neither saved as open nor in the active trail, close it.
  if ($menu && !($in_active_trail || in_array($item['localized_options']['attributes']['id'], $cookie))) {
    $extra_class .= ' collapsed start-collapsed ';
  }

  // Cascade up to the original theming function.
  return $function($link, $has_children, $menu, $in_active_trail, $extra_class);
}