From 27f055b5cd7e545acd3460d67209b769e389ff18 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Tue, 7 Sep 2004 21:48:49 +0000
Subject: [PATCH] - Patch #10192 by JonBob: fixed issue with menus not
 expanding.

---
 includes/menu.inc | 52 +++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/includes/menu.inc b/includes/menu.inc
index 1fe9cf0da686..26354247d70d 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -701,29 +701,45 @@ function _menu_build() {
   if (module_exist('menu')) {
     $result = db_query('SELECT * FROM {menu} ORDER BY mid ASC');
     while ($item = db_fetch_object($result)) {
-      // Don't display non-custom menu items if no module declared them.
-      if (!($item->type & MENU_CREATED_BY_ADMIN) && array_key_exists($item->path, $_menu['path index'])) {
+      if (array_key_exists($item->path, $_menu['path index'])) {
+        // The path is already declared.
         $old_mid = $_menu['path index'][$item->path];
-        $_menu['items'][$item->mid] = $_menu['items'][$old_mid];
-        unset($_menu['items'][$old_mid]);
-        $_menu['path index'][$item->path] = $item->mid;
-        // If administrator has changed item position, reflect the change.
-        if ($item->type & MENU_MODIFIED_BY_ADMIN) {
-          $_menu['items'][$item->mid]['title'] = $item->title;
-          $_menu['items'][$item->mid]['description'] = $item->description;
-          $_menu['items'][$item->mid]['pid'] = $item->pid;
-          $_menu['items'][$item->mid]['weight'] = $item->weight;
-          $_menu['items'][$item->mid]['type'] = $item->type;
+        if ($old_mid < 0) {
+          // It had a temporary ID, so use a permanent one.
+          $_menu['items'][$item->mid] = $_menu['items'][$old_mid];
+          unset($_menu['items'][$old_mid]);
+          $_menu['path index'][$item->path] = $item->mid;
+        }
+        else {
+          // It has a permanent ID. Only replace with non-custom menu items.
+          if ($item->type & MENU_CREATED_BY_ADMIN) {
+            $_menu['items'][$item->mid] = array('path' => $item->path, 'access' => TRUE, 'callback' => '', 'callback arguments' => array());
+          }
+          else {
+            // Leave the old item around as a shortcut to this one.
+            $_menu['items'][$item->mid] = $_menu['items'][$old_mid];
+            $_menu['path index'][$item->path] = $item->mid;
+          }
         }
       }
-      // Next, add any custom items added by the administrator.
-      else if ($item->type & MENU_CREATED_BY_ADMIN) {
-        $_menu['items'][$item->mid] = array('pid' => $item->pid, 'path' => $item->path, 'title' => $item->title, 'description' => $item->description, 'access' => TRUE, 'weight' => $item->weight, 'type' => $item->type, 'callback' => '', 'callback arguments' => array());
-
-        if (!empty($item->path) && !array_key_exists($item->path, $_menu['path index'])) {
-          $_menu['path index'][$item->path] = $item->mid;
+      else {
+        // The path was not declared, so this is a custom item or an orphaned one.
+        if ($item->type & MENU_CREATED_BY_ADMIN) {
+          $_menu['items'][$item->mid] = array('path' => $item->path, 'access' => TRUE, 'callback' => '', 'callback arguments' => array());
+          if (!empty($item->path)) {
+            $_menu['path index'][$item->path] = $item->mid;
+          }
         }
       }
+
+      // If the administrator has changed the item, reflect the change.
+      if ($item->type & MENU_MODIFIED_BY_ADMIN) {
+        $_menu['items'][$item->mid]['title'] = $item->title;
+        $_menu['items'][$item->mid]['description'] = $item->description;
+        $_menu['items'][$item->mid]['pid'] = $item->pid;
+        $_menu['items'][$item->mid]['weight'] = $item->weight;
+        $_menu['items'][$item->mid]['type'] = $item->type;
+      }
     }
   }
 
-- 
GitLab