Download & Extend

Multiple menu entires feature break local menu with non-standard menu use

Project:Local Menu
Version:6.x-1.7
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community

Issue Summary

I use Drupal menus in slightly non-standard way, and the new multiple menu entries features breaks local menu in my site.

I have a bilingual site, with the content similar but not identical across the languages.

I don't use either primary or secondary links on my site (in build/menu/settings, source for both primary and secondary links is set to "no"). Instead I have a special per-language menu, and I have an explicit code in my theme that display the correct menu using the $language variable.

As my menus aren't standard, this loop (lines 72-82) never breaks, and $link isn't set at the end of the loop:

<?php
  
while ($link = menu_link_load(db_result($result))) {
       
      if (
in_array($link['menu_name'], array(
           
variable_get('menu_primary_links_source', 'primary-links'),
           
variable_get('menu_secondary_links_source', 'secondary-links'),
           
menu_get_active_menu_name(),
          ))) {
        break;
      }
    }
?>

I think the solution is that $link should by default contain the first value.

Comments

#1

All that code (and the while loop it's a part of) is saying is to check the primary-links, then secondary-links and then the current active menu to see if the node is in them and if it is, then break out of the WHILE loop with one of those 3 menus as the
menu_set_active_menu_name($link['menu_name']);
is called.

If the node isn't in one of those 3 menus that it'll be part of the last menu that the SQL result found. There's no ordering set for the SQL call, so it'll be the latest one that was entered.

I can't wait for weights :)

#2

Actually, there's all these references to the $link object after the while loop. Doesn't $link have to be set to global or something? I'm doing printouts and the $link is empty outside the while, but it's populated inside the while.

I'd say this module is broken if that's the case...?

I added these 3 lines to get it to work:

menu_set_active_menu_name($link['menu_name']);  // this was outside the while - I brought it inside
$depth = $link['depth']; // added#1
    } // this closes the while loop
$link['menu_name'] = menu_get_active_menu_name(); // added#2
$link['depth'] = $depth; // added#3

#3

Status:active» needs review

Just remember the last db result...

<?php
   
// In case there are multiple, let's find the most appropriate one
   
$last_link = array();
    while (
$link = menu_link_load(db_result($result))) {
//drupal_set_message('<pre>' . print_r($link, TRUE) . '</pre>');
     
if (in_array($link['menu_name'], array(
           
variable_get('menu_primary_links_source', 'primary-links'),
           
variable_get('menu_secondary_links_source', 'secondary-links'),
           
menu_get_active_menu_name(),
          ))) {
        break;
      }
     
$last_link = $link;
    }
   
    if (empty(
$link)) {
     
$link = $last_link;
    }
?>

#4

The while loop calls menu_link_load() using the last result of db_result() which is FALSE when all rows are read. This in turn assigns FALSE to $link as the last step.

Solution is to not call menu_link_load() in the while() statement itself but inside the while loop. The attached patch fixes this.

AttachmentSize
local_menu-575930-4.patch 747 bytes

#5

Version:6.x-1.6» 6.x-1.7

Problem still not solved. Patch for 6.x-1.7 attached.

AttachmentSize
local_menu-575930-5.patch 751 bytes

#6

Status:needs review» reviewed & tested by the community

Actually I got this same solution today and I was getting in here to post the patch, but I just notice this is the same patch I made.
I can confirm that this patch works and it solve several issues related with menus not showing up.
It's all because at the last check of the while it will set $link as false overriding the value that we were looking for, by doing this the value of $link will not be override.

Please go ahead and add this patch to the module.
Thanks fuerst.

Best regards,
Nestor

nobody click here