Drupal – Menu items were not expanded in multilingual site

Normally, the Drupal Menu will be expanded automatically whenever the menu item itself or its children are active. But if you have more than one menu item pointing to the same path such as having the same menu items in different language inside a menu, the auto expand does not work.

Applying the following patch to <drupal_root>/includes/menu.inc could solve the problem.

Index: menu.inc
===================================================================
--- menu.inc	(revision 181)
+++ menu.inc	(working copy)
@@ -867,11 +867,12 @@
  */
 function menu_tree_page_data($menu_name = 'navigation') {
   static $tree = array();
+  global $language;
 
   // Load the menu item corresponding to the current page.
   if ($item = menu_get_item()) {
     // Generate a cache ID (cid) specific for this page.
-    $cid = 'links:'. $menu_name .':page-cid:'. $item['href'] .':'. (int)$item['access'];
+    $cid = 'language:'. $language->language  .':links:'. $menu_name .':page-cid:'. $item['href'] .':'. (int)$item['access'];
 
     if (!isset($tree[$cid])) {
       // If the static variable doesn't have the data, check {cache_menu}.
@@ -895,7 +896,18 @@
             $args[] = '<front>';
             $placeholders .= ", '%s'";
           }
-          $parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path IN (". $placeholders .")", $args));
+          $res = db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8, options FROM {menu_links} WHERE menu_name = '%s' AND link_path IN (". $placeholders .")", $args);
+          $parents = array();
+          while ($menu_data = db_fetch_array($res)) {
+            $options = unserialize($menu_data['options']);
+            if (($options['langcode'] == $language->language)) {
+              $parents = $menu_data;
+              break;
+            } elseif (empty($parents)) {
+              $parents = $menu_data;
+            }
+          }
+          unset($parents['options']);
 
           if (empty($parents)) {
             // If no link exists, we may be on a local task that's not in the links.

 

Please note that this patch is applied to the Drupal core, make sure you have backed up the file before patching it.

Done =)

Reference:

2 thoughts on “Drupal – Menu items were not expanded in multilingual site”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.