Consider the following situation:
- Let's say that you have a menu "menu-my-menu" that you have removed on purpose from default active menus by calling menu_set_active_menu_names()
.
This may happen if you have decided to display different menus based on, for instance, user role or language.
- Do something, like editing a menu link in this menu, that clears its cache.
- On a new page request to a path that is present in different menus, including the unallowed "menu-my-menu", menu_tree_page_data()
may be called and cache be rebuilt for the requested path. At this point, menu_link_get_preferred($active_path, $menu_name)
will be called with
"menu-my-menu" as $menu_name.
- Next, on breadcrumb build (in the same page request), menu_link_get_preferred()
will be called again without parameters. The problem is that at this point, menu_link_get_preferred()
will not check menu_set_active_menu_names()
and may return a link from "menu-my-menu" for breadcrumb.
Comments
Comment #1
anrikun CreditAttribution: anrikun commentedHere is patch for D8.
It simply adds an extra condition to prevent a menu link from an non-allowed menu from being stored as the most specific link.
Comment #1.0
anrikun CreditAttribution: anrikun commentedA word was missing.
Comment #1.1
anrikun CreditAttribution: anrikun commentedFixed wrong markup
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedThere is indeed a bug here, but it's basically a caching issue: the preferred link is computed in a context and used in another.
It would be easier and make more sense to remove the
MENU_PREFERRED_LINK
hack and just pick: (1) the link of the specified menu if it exists (ie.$preferred_links[$path][$menu_name]
) or else (2) the most specific link (ie.reset($preferred_links[$path])
) if it doesn't.Comment #3
anrikun CreditAttribution: anrikun commentedThere you are!
I didn't want to introduce too much change because I thought it wouldn't be appreciated, but if you say so :-)
Extra change: we now initialize $preferred_links[$path] to an empty array so that if no match is found, code is not needlessly run again on the next call.
Comment #4
Damien Tournoud CreditAttribution: Damien Tournoud commentedI'm happy with #3, but we probably need to extend / write some tests.
Comment #5
Damien Tournoud CreditAttribution: Damien Tournoud commentedCandidate for backport.
Comment #6
anrikun CreditAttribution: anrikun commented+ I think tag 'translatable' should be added to the query because it is present in _menu_build_tree(), and again a wrong preferred link could be picked up if query is altered in _menu_build_tree() but not in menu_link_get_preferred().
Should we open a separate issue for this?
Comment #7
anrikun CreditAttribution: anrikun commentedI still had problems and I noticed that I had skipped another strange part in my previous patch:
What???
This updated patch removes it.
Comment #9
anrikun CreditAttribution: anrikun commentedThere is another bug: menu.module retrieves variable 'menu_default_active_menus' using a different default value from the one used in menu.inc
New patch.
When backporting to D7, we must not forget to add an install update for that.
Comment #10
anrikun CreditAttribution: anrikun commentedWhile writing tests, I found another bug: menu_tree_page_data() should cache separately a menu when it is active and when it is not.
Comment #11
anrikun CreditAttribution: anrikun commentedAdded tests. Still incomplete though but let's see if they pass.
Comment #12
anrikun CreditAttribution: anrikun commentedTests should be OK now. Let's test the test-only patch and the full one.
Comment #13
anrikun CreditAttribution: anrikun commentedChanging title to better reflect the issue.
Comment #13.0
anrikun CreditAttribution: anrikun commentedFixes wrong mark-up again!
Comment #14
anrikun CreditAttribution: anrikun commentedThe same patch for D7 (without tests). Let's see if it passes the tests.
Comment #15
anrikun CreditAttribution: anrikun commentedNow with the tests: tests only and full patches
Comment #16
anrikun CreditAttribution: anrikun commentedOk patch for D7 works too.
It still lacks the install update part though.
Back to D8 for now.
Comment #17
anrikun CreditAttribution: anrikun commentedRe-uploading D8 patches with small improvements on #12:
- added a new condition to select only menu links from active menus
- one comment fix
Tests are unchanged.
Comment #18
cweagansFixing tags per http://drupal.org/node/1517250
Comment #19
anrikun CreditAttribution: anrikun commentedCompleted patch for D7 (see #16).
Comment #20
sun#3 made sense to me, but starting from #9, various other changes have been added to the patch, without really explaining what's happening under which circumstances and why the changes are needed.
Some of the changes seem to partially revert the fixes from #942782: Custom menus never receive an active trail -- we need to make sure to not introduce a regression.
Comment #20.0
sunUpdated text to match the new title.
Comment #23
jhedstromComment #24
rteijeiro CreditAttribution: rteijeiro at Tieto commentedI'm closing this as outdated as the menu module doesn't exists anymore. Feel free to reopen and update the issue summary if the problem still persists.