You are here

function theme_dhtml_menu_item in DHTML Menu 6.2

Same name and namespace in other branches
  1. 5 dhtml_menu.module \theme_dhtml_menu_item()
  2. 6 dhtml_menu.inc \theme_dhtml_menu_item()

Theme each menu item, adding important CSS data

1 theme call to theme_dhtml_menu_item()
theme_dhtml_menu_tree in ./dhtml_menu.theme.inc
Theme each menu, adding important CSS data

File

./dhtml_menu.theme.inc, line 13
dhtml_menu.inc Themable functions required to render a DHTML menu block

Code

function theme_dhtml_menu_item($item, $id) {
  static $expanded = NULL;
  if (!is_array($expanded)) {
    if (!isset($_COOKIE['dhtml_menu'])) {
      $_COOKIE['dhtml_menu'] = '';
    }
    $expanded = explode(',', $_COOKIE['dhtml_menu']);
  }

  // Unset hidden sub-items. This avoids items with empty, all-hidden sub-menus.
  if (!empty($item['below'])) {
    foreach ($item['below'] as $index => $leaf) {
      if ($leaf['link']['hidden']) {
        unset($item['below'][$index]);
      }
    }
  }

  // Check if the menu item has a submenu
  // If no, create a normal menu item
  // If yes, create the submenu too
  if (empty($item['below'])) {
    return '  <li class="leaf" id="menu-leaf' . $id . '">' . theme('menu_item_link', $item['link']) . "</li>\n";
  }
  else {
    $type = isset($item['link']['type']) ? $item['link']['type'] : NULL;
    if ($item['link']['in_active_trail'] || $item['link']['expanded'] || in_array("sub{$id}", $expanded)) {
      $state = 'expanded';
      $display = '';
    }
    else {
      $state = 'collapsed';
      $display = ' style="display: none;"';
    }
    return "<li class=\"menutitle {$state}\" id=\"menu-sub{$id}\">" . theme('menu_item_link', $item['link']) . "<div class=\"submenu\" id=\"sub{$id}\"{$display}>" . theme('dhtml_menu_tree', $item['below'], $item['link'], $id) . '</div>' . '</li>';
  }
}