Return to Snippet

Revision: 20284
at November 11, 2009 10:15 by Ateneatech


Updated Code
...
$data = menu_find_active_trail(menu_tree_all_data(...));
...

/**
 * Wrapper function
 */
function menu_find_active_trail(&$menu_tree) {
  $item = menu_get_item();
  _menu_find_active_trail($menu_tree, $item);
  return $menu_tree;
}

/**
 * Recursive function to find the active menu and the active trail in the given tree.
 */
function _menu_find_active_trail(&$menu_tree, $item) {
  $level_is_expanded = FALSE;
  foreach($menu_tree as &$menu_item) {
    $link = &$menu_item['link'];
    if ($link['href']==$item['href']) { // Found the exact location in the tree
      $link['active'] = TRUE;
      $link['in_active_trail'] = TRUE;
      return true;
    } else {
      if ($link['has_children']) {
        $result = _menu_find_active_trail($menu_item['below'], $item);
        $link['in_active_trail'] = $result;
        if ($result) $level_is_expanded = TRUE;
      }
    }
  }
  return $level_is_expanded;
}

Revision: 20283
at November 11, 2009 10:15 by Ateneatech


Initial Code
...
$data = menu_find_active_trail(menu_tree_all_data(...));
...

/**
 * Wrapper function
 */
function menu_find_active_trail(&$menu_tree) {
  $item = menu_get_item();
  _menu_find_active_trail($menu_tree, $item);
  return $menu_tree;
}
/**
 * Recursive function to find the active menu and the active trail in the given tree.
 */
function _menu_find_active_trail(&$menu_tree, $item) {
  $level_is_expanded = FALSE;
  foreach($menu_tree as &$menu_item) {
    $link = &$menu_item['link'];
    if ($link['href']==$item['href']) { // Found the exact location in the tree
      $link['active'] = TRUE;
      $link['in_active_trail'] = TRUE;
      return true;
    } else {
      if ($link['has_children']) {
        $result = _menu_find_active_trail($menu_item['below'], $item);
        $link['in_active_trail'] = $result;
        if ($result) $level_is_expanded = TRUE;
      }
    }
  }
  return $level_is_expanded;
}

Initial URL


Initial Description
Via: [http://www.touchdesk.nl/2009/04/full-menu-tree-with-active-trail-in-drupal-6/](http://www.touchdesk.nl/2009/04/full-menu-tree-with-active-trail-in-drupal-6/)

Initial Title
Add 'active_trail' class to a 'menu_tree_all_data' result

Initial Tags
drupal

Initial Language
PHP