Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.282
diff -u -p -r1.282 menu.inc
--- includes/menu.inc	10 Jul 2008 10:58:01 -0000	1.282
+++ includes/menu.inc	20 Aug 2008 11:50:25 -0000
@@ -1536,16 +1536,26 @@ function menu_set_active_item($path) {
 
 /**
  * Set (or get) the active trail for the current page - the path to root in the menu tree.
+ *
+ * @param $new_trail
+ *   An array of links that overrides the default trail.
+ * @param $active_menu_name
+ *   The menu tree in which to set (or get) the active trail.
  */
-function menu_set_active_trail($new_trail = NULL) {
+function menu_set_active_trail($new_trail = NULL, $active_menu_name = NULL) {
   static $trail;
 
+  // The trail can vary depending on the active menu.
+  if (empty($active_menu_name)) {
+    $active_menu_name = menu_get_active_menu_name();
+  }
+
   if (isset($new_trail)) {
-    $trail = $new_trail;
+    $trail[$active_menu_name] = $new_trail;
   }
-  elseif (!isset($trail)) {
-    $trail = array();
-    $trail[] = array('title' => t('Home'), 'href' => '<front>', 'localized_options' => array(), 'type' => 0);
+  elseif (empty($trail[$active_menu_name])) {
+    $trail[$active_menu_name] = array();
+    $trail[$active_menu_name][] = array('title' => t('Home'), 'href' => '<front>', 'localized_options' => array(), 'type' => 0);
     $item = menu_get_item();
 
     // Check whether the current item is a local task (displayed as a tab).
@@ -1569,19 +1579,19 @@ function menu_set_active_trail($new_trai
       }
     }
 
-    $tree = menu_tree_page_data(menu_get_active_menu_name());
+    $tree = menu_tree_page_data($active_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'];
+        $trail[$active_menu_name][] = $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'];
+          $trail[$active_menu_name][] = $curr['link'];
           $tree = $curr['below'] ? $curr['below'] : array();
         }
         list($key, $curr) = each($tree);
@@ -1589,19 +1599,22 @@ function menu_set_active_trail($new_trai
     }
     // 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;
+    $last = count($trail[$active_menu_name]) - 1;
+    if ($trail[$active_menu_name][$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) {
+      $trail[$active_menu_name][] = $item;
     }
   }
-  return $trail;
+  return $trail[$active_menu_name];
 }
 
 /**
  * Get the active trail for the current page - the path to root in the menu tree.
+ *
+ * @param $active_menu_name
+ *   The menu tree from which to get the active trail.
  */
-function menu_get_active_trail() {
-  return menu_set_active_trail();
+function menu_get_active_trail($active_menu_name = NULL) {
+  return menu_set_active_trail(NULL, $active_menu_name);
 }
 
 /**
@@ -1619,6 +1632,12 @@ function menu_get_active_breadcrumb() {
   if ($item && $item['access']) {
     $active_trail = menu_get_active_trail();
 
+    // If the active trail consist only of "home" and the "active item", check
+    // the primary links menu for a better trail.
+    if (count($active_trail) < 3) {
+      $active_trail = menu_get_active_trail(variable_get('menu_primary_links_source', 'primary-links'));
+    }
+
     foreach ($active_trail as $parent) {
       $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);
     }
