You are here

function theme_dhtml_menu_tree in DHTML Menu 6.2

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

Theme each menu, adding important CSS data

2 theme calls to theme_dhtml_menu_tree()
theme_dhtml_menu_item in ./dhtml_menu.theme.inc
Theme each menu item, adding important CSS data
_dhtml_menu_build_block in ./dhtml_menu.module
Build a specific DHTML Menu block's content.

File

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

Code

function theme_dhtml_menu_tree($tree, $parent = NULL, $pid = NULL) {

  // If no further items, return blank
  if (empty($tree)) {
    return '';
  }
  $add_links = _dhtml_get_add_links();
  $output = '';
  if ($parent && isset($add_links[$parent['link_path']])) {
    $duplication = $parent;
    if ($add_links[$parent['link_path']] !== TRUE) {
      $duplication['title'] = $add_links[$parent['link_path']];
    }
    $output .= '<li class="leaf" id="menu-leaf' . $pid . '">' . theme('menu_item_link', $duplication) . "</li>\n";
  }
  $class = 'menu';
  if ($parent == NULL) {
    $class .= ' menu-root';

    // Add the proper JS file
    drupal_add_js(drupal_get_path('module', 'dhtml_menu') . '/dhtml_menu.js');

    // If the effect is on, tell it to JS
    if ($effects = variable_get('dhtml_menu_use_effects', 0)) {
      drupal_add_js(array(
        'dhtmlMenu_useEffects' => 1,
      ), 'setting');
    }

    // If Hide Siblings is on, tell it to JS
    if ($effects = variable_get('dhtml_menu_hide_siblings', 0)) {
      drupal_add_js(array(
        'dhtmlMenu_hideSiblings' => 1,
      ), 'setting');
    }
  }
  foreach ($tree as $pid => $item) {

    // hidden sub-items are removed already; this line takes care of root items.
    if ($item['link']['hidden']) {
      continue;
    }

    // pid is going to be a DOM identifier, and can't have some characters
    $pid = ereg_replace('[^A-Za-z0-9]', '', $pid);
    $output .= theme('dhtml_menu_item', $item, $pid);
  }
  return "\n<ul class=\"{$class}\">\n" . $output . "\n</ul>\n";
}