You are here

function menu_position_get_active_trail in Menu Position 6

Retrieve the active trail for the specified menu.

Copy of menu_set_active_trail() without the brain-dead static cache.

1 call to menu_position_get_active_trail()
menu_position_evaluate_rules in ./menu_position.module
Evaluates all rules based on the given path.

File

./menu_position.module, line 232
Provides menu links for dynamic positioning of nodes based on configurable rules.

Code

function menu_position_get_active_trail($menu_name = NULL) {
  if (!isset($menu_name)) {
    $menu_name = menu_get_active_menu_name();
  }
  $trail = array();
  $trail[] = array(
    'title' => t('Home'),
    'href' => '<front>',
    'localized_options' => array(),
    'type' => 0,
  );
  $item = menu_get_item();

  // We know the current item isn't a local task, so we've removed some lines
  // from our copy of menu_set_active_trail().
  $tree = menu_tree_page_data($menu_name);
  list($key, $curr) = each($tree);
  while ($curr) {

    // Terminate the loop when we find the current path in the active trail.
    if ($curr['link']['href'] == $item['href']) {
      $trail[] = $curr['link'];
      $curr = FALSE;
    }
    else {

      // Add the link if it's in the active trail, then move to the link below.
      if ($curr['link']['in_active_trail']) {
        $trail[] = $curr['link'];
        $tree = $curr['below'] ? $curr['below'] : array();
      }
      list($key, $curr) = each($tree);
    }
  }

  // Make sure the current page is in the trail (needed for the page title),
  // but exclude tabs and the front page.
  $last = count($trail) - 1;
  if ($trail[$last]['href'] != $item['href'] && !(bool) ($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) {
    $trail[] = $item;
  }
  return $trail;
}