This is an issue that was fixed on the D6 branch, unfortunately it is back in the D7 branch. The problem lies with Drupal Core, however I wanted to report it here as there is a work around other people might like to know about.

Problem

If you have a menu like this:
A
- A1
-- A1.1
- A2
etc.

Such that A and A1 point to the same path (for instance because you want the page at A to have a default subsection - A1), then *under some circumstances* menu block will not expand the sub-menus of A1.

Cause of the problem

The problem is that the Drupal core function "menu_tree_page_data", which returns the menu with items that are not part of the active trail trimmed, wrongly trims the A1.1 sub-menu away.

The reason it does this is because it does not think that A1 is in the active trail - because, for the current path, it found A in the active trail which, under some circumstances, prevail over A1. This problem happens in a function called "menu_link_get_preferred", which assumes there is only one candidate per path for the active trail.

Workaround

As I said, this only happens under some circumstances, and there is a work around. When there is two candidates for the same path, the 'menu_link_get_preferred' function uses the last one that was returned by the database query. The query is not ordered - so it uses the last one that the database returns.

So: if you run into this problem, the work around is simply to exchange your two menu items. Rename 'A' to 'A1' and rename 'A1' to 'A', then change their positions in the menu hierarchy. Now the function 'menu_link_get_prefered' will return the new 'A1' instead of 'A', and everything will work as expected.

Comments

Alice Heaton’s picture

There is a related Core issue here : http://drupal.org/node/1649062

This would not fix the problem (it proposes that the query in 'menu_link_get_preferred' should be sorted by the mlid), but it would make the problem - and the workaround - more consistent.

I will post a link to this issue there.

JohnAlbin’s picture

Status: Active » Closed (works as designed)