From 7bb88809b7eb4bf8cb410f6234bfe1ba43e553a2 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Tue, 6 Jul 2004 07:33:59 +0000
Subject: [PATCH] - Patch #9049 by JonBob: fixed a number of tab issues.

---
 includes/menu.inc        | 55 +++++++++++++++++++++++++++++++---------
 misc/drupal.css          |  5 ++--
 modules/book.module      |  2 +-
 modules/book/book.module |  2 +-
 modules/poll.module      |  5 ++--
 modules/poll/poll.module |  5 ++--
 6 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/includes/menu.inc b/includes/menu.inc
index 330a56c698b2..33429c89b57b 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -100,7 +100,6 @@
  */
 function menu_get_menu() {
   global $_menu;
-  global $user;
 
   if (!isset($_menu['items'])) {
     // _menu_build() may indirectly call this function, so prevent infinite loops.
@@ -108,6 +107,20 @@ function menu_get_menu() {
     _menu_build();
   }
 
+  return $_menu;
+}
+
+/**
+ * Return the local task tree.
+ *
+ * Unlike the rest of the menu structure, the local task tree cannot be cached
+ * nor determined too early in the page request, because the user's current
+ * location may be changed by a menu_set_location() call, and the tasks shown
+ * (just as the breadcrumb trail) need to reflect the changed location.
+ */
+function menu_get_local_tasks() {
+  global $_menu;
+
   // Don't cache the local task tree, as it varies by location and tasks are
   // allowed to be dynamically determined.
   if (!isset($_menu['local tasks'])) {
@@ -117,7 +130,7 @@ function menu_get_menu() {
     _menu_build_local_tasks();
   }
 
-  return $_menu;
+  return $_menu['local tasks'];
 }
 
 /**
@@ -275,6 +288,24 @@ function menu_get_active_nontask_item() {
   }
 }
 
+/**
+ * Returns the ID of the current menu item or, if the current item is a
+ * local task or subtask, the ID of the current local task (not subtask).
+ */
+function menu_get_active_local_task() {
+  $menu = menu_get_menu();
+  $mid = menu_get_active_item();
+
+  // Find the first non-task item:
+  while ($mid && ($menu['items'][$mid]['type'] & MENU_LOCAL_SUBTASK)) {
+    $mid = $menu['items'][$mid]['pid'];
+  }
+
+  if ($mid) {
+    return $mid;
+  }
+}
+
 /**
  * Returns the title of the active menu item.
  */
@@ -434,20 +465,20 @@ function theme_menu_item($mid) {
  * them as tabs.
  */
 function theme_menu_local_tasks() {
-  $menu = menu_get_menu();
+  $local_tasks = menu_get_local_tasks();
   $output = '';
 
-  if (count($menu['local tasks'][0]['children'])) {
+  if (count($local_tasks[0]['children'])) {
     $output .= "<ul class=\"tabs primary\">\n";
-    foreach ($menu['local tasks'][0]['children'] as $mid) {
-      $output .= theme('menu_local_task', $mid, menu_in_active_trail($mid));
+    foreach ($local_tasks[0]['children'] as $mid) {
+      $output .= theme('menu_local_task', $mid, $mid == menu_get_active_local_task());
     }
     $output .= "</ul>\n";
 
-    foreach ($menu['local tasks'][0]['children'] as $mid) {
-      if (menu_in_active_trail($mid) && count($menu['local tasks'][$mid]['children'])) {
+    foreach ($local_tasks[0]['children'] as $mid) {
+      if ($mid == menu_get_active_local_task() && count($local_tasks[$mid]['children'])) {
         $output .= "<ul class=\"tabs secondary\">\n";
-        foreach ($menu['local tasks'][$mid]['children'] as $cid) {
+        foreach ($local_tasks[$mid]['children'] as $cid) {
           $output .= theme('menu_local_task', $cid, menu_in_active_trail($cid));
         }
         $output .= "</ul>\n";
@@ -699,9 +730,6 @@ function _menu_build_local_tasks() {
 
   $mid = menu_get_active_nontask_item();
   if ($mid) {
-    $tasks[$mid] = array('title' => $_menu['items'][$mid]['title'], 'path' => $_menu['items'][$mid]['path'], 'children' => array());
-    $tasks[0]['children'][] = $mid;
-
     // Find top-level tasks
     if ($children = $_menu['items'][$mid]['children']) {
       foreach ($children as $cid) {
@@ -713,6 +741,9 @@ function _menu_build_local_tasks() {
     }
     usort($tasks[0]['children'], '_menu_sort');
 
+    $tasks[$mid] = array('title' => $_menu['items'][$mid]['title'], 'path' => $_menu['items'][$mid]['path'], 'children' => array());
+    array_unshift($tasks[0]['children'], $mid);
+
     // Find subtasks
     foreach ($tasks[0]['children'] as $mid) {
       if ($children = $_menu['items'][$mid]['children']) {
diff --git a/misc/drupal.css b/misc/drupal.css
index 757df19725da..0316f628b2ab 100644
--- a/misc/drupal.css
+++ b/misc/drupal.css
@@ -420,8 +420,9 @@ ul.primary li a:hover {
   border-bottom-color: #eee;
 }
 ul.secondary {
-  padding: 0;
-  margin: 0.5em 2em 1em;
+  border-bottom: 1px solid #bbb;
+  padding: 0.5em 1em 0.5em 1em;
+  margin: 5px;
 }
 ul.secondary li {
   display: inline;
diff --git a/modules/book.module b/modules/book.module
index d5802fb33d2a..50aae88f6e61 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -573,7 +573,7 @@ function book_navigation($node) {
   foreach ($path as $level) {
     $node->breadcrumb[] = array('path' => 'book/view/'. $level->nid, 'title' =>  $level->title);
   }
-  $node->breadcrumb[] = array('path' => 'book/view/'. $node->nid);
+  $node->breadcrumb[] = array('path' => 'node/'. $node->nid);
 
   if ($node->nid) {
     $output .= '<div class="book">';
diff --git a/modules/book/book.module b/modules/book/book.module
index d5802fb33d2a..50aae88f6e61 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -573,7 +573,7 @@ function book_navigation($node) {
   foreach ($path as $level) {
     $node->breadcrumb[] = array('path' => 'book/view/'. $level->nid, 'title' =>  $level->title);
   }
-  $node->breadcrumb[] = array('path' => 'book/view/'. $node->nid);
+  $node->breadcrumb[] = array('path' => 'node/'. $node->nid);
 
   if ($node->nid) {
     $output .= '<div class="book">';
diff --git a/modules/poll.module b/modules/poll.module
index 5ee083a5451b..45bd9fa2e844 100644
--- a/modules/poll.module
+++ b/modules/poll.module
@@ -304,9 +304,9 @@ function poll_teaser($node) {
  */
 function poll_view_voting(&$node, $main, $page, $block) {
   $url = request_uri();
-  $output .= '<div class="poll">';
+  $output = '<div class="poll">';
 
-  $form .= '<div class="vote-form">';
+  $form = '<div class="vote-form">';
   $form .= '<div class="choices">';
   if ($node->choice) {
     $list = array();
@@ -415,6 +415,7 @@ function poll_vote(&$node) {
  */
 function poll_view(&$node, $main = 0, $page = 0, $block = 0) {
   global $user;
+  $output = '';
 
   if ($node->allowvotes && ($block || arg(2) != 'results')) {
     $output .= poll_view_voting($node, $main, $page, $block);
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index 5ee083a5451b..45bd9fa2e844 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -304,9 +304,9 @@ function poll_teaser($node) {
  */
 function poll_view_voting(&$node, $main, $page, $block) {
   $url = request_uri();
-  $output .= '<div class="poll">';
+  $output = '<div class="poll">';
 
-  $form .= '<div class="vote-form">';
+  $form = '<div class="vote-form">';
   $form .= '<div class="choices">';
   if ($node->choice) {
     $list = array();
@@ -415,6 +415,7 @@ function poll_vote(&$node) {
  */
 function poll_view(&$node, $main = 0, $page = 0, $block = 0) {
   global $user;
+  $output = '';
 
   if ($node->allowvotes && ($block || arg(2) != 'results')) {
     $output .= poll_view_voting($node, $main, $page, $block);
-- 
GitLab