In menu_tree_build(), the "current page" is determined by a simple query to {menu_links} based on $_GET['q']

In most cases, this is fine, because if the current page is part of the menu system, then $_GET['q'] will be one and same with the active menu item returned by menu_get_active_trail(). However in some cases, e.g. when menu_set_active_trail() is invoked to change the active trail for a given page, $_GET['q'] doesn't match the active trail.

The attached patch updates menu_tree_build() to use the active trail instead of $_GET['q'].
Maybe this should be a configuration option?
I'm not sure.

Anyway, the patch works for what I need it to do.
Please let me know if it could be considered for inclusion, or how I might update it to be considered.
Thanks for the great module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AaronBauman’s picture

Updated to loop on active trail array.

AaronBauman’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
FileSize
2.19 KB

This issue persists into 7.x

AaronBauman’s picture

Title: Make active menu selection use menu_get_active_trail() instead of $_GET['q'] » Examine entire active trail to find a relevant menu, instead of just the current page

This issue persists, although a partial solution has been deployed in 7.x-2.x
Updated title to be more specific

JohnAlbin’s picture

Examine entire active trail to find a relevant menu, instead of just the current page

Ok. So the issue scope has changed from the issue summary. Can you explain why you'd want to examine the entire active trail instead of just the active page?

AaronBauman’s picture

If the full menu tree isn't built, this function bails, and the proper menu_block doesn't get rendered.
I haven't identified under which conditions the menu tree is incomplete.

JohnAlbin’s picture

If the full menu tree isn't built, this function bails, and the proper menu_block doesn't get rendered.

Huh? If the current page isn't in any menu, the menu tree doesn't need to be built. That's by design. You seem to want to change the design. I was asking why.

AaronBauman’s picture

I'm saying sometimes the menu tree doesn't get built, even though the current page is in the menu.
I've noticed this behavior most recently when using Menu Position module.

I'm not intimately familiar with the menu system, but I think this could happen when menu_set_active_trail() is invoked after the menu tree has already been built.

JohnAlbin’s picture

That sounds like #1524674: Use of $_GET['q'] ignores menu_position module which is fixed in the 7.x-2.x-dev version.

AaronBauman’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev

OK, I will take your word for it on D7.
I'm hitting this issue on a 6.x site, which I realize is reaching end of life, so please change status as you see fit.

JohnAlbin’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)