Closed (duplicate)
Project:
Drupal core
Version:
6.3
Component:
menu system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
31 Jul 2008 at 22:58 UTC
Updated:
6 Dec 2010 at 21:00 UTC
menu_get_active_menu_name() appears to be essentially unimplemented -- it always returns the string 'navigation' instead of, for example, 'primary-links'.
Is there any other way to ask Drupal "What menu am I in?" Unlike Drupal 5, menu_get_active_trail() doesn't include the root menu name, only the links.
I'd like to get the root menu for controlling block visibility - e.g. only show a particular block if the page is in the 'primary-links' menu.
Thanks!
Comments
Comment #1
kjay commentedI also am finding the same thing. I am running version 6.6 and the menu_get_active_menu_name function always returns 'navigation'. Is this anything others have experienced or can shed some light on?
Comment #2
grendzy commentedYes, it seems that others are interested in working on this as well:
#184955: menu_get_active_breadcrumb breaks breadcrumbs in primary links
My guess is this behavior won't be changed until Drupal 7. Partly, because a particular path can be in more than one menu, so the correct active trail can be ambiguous (one proposed solution is to add weights to the menus).
In the meantime, this module has been working really well for me:
http://drupal.org/project/menu_breadcrumb
It's advertised as a breadcrumb tweak -- but IIRC it also sets menu_get_active_menu_name.
Comment #3
glass.dimly commentedWe found some code in ctools that fixed this problem for us:
http://drupal.org/node/791862
Comment #4
glass.dimly commentedFYI the code was
Comment #5
jm.federico commentedThanks for that code.
One question though, what are the last two lines for?
Thanks again.
Comment #6
jck4 commentedThanks grendzy - I was banging my head trying to get this to work, and I'm not much of a coder as yet, so installing menu_breadcrumbs worked for me. I was trying to switch a header image based on the Primary Menu top level, as described here: http://www.focal55.com/blog/drupal-6-tutorial-find-menu-parent-item-page..., and I could never get menu_get_active_menu_name() to return ['link_title'], until I cam across this thread.
Much thanks!
Comment #7
glass.dimly commentedYou could also just try enabling ctools and see if that fixes it, since the code in #5 is in ctools.
Oh, and jm.frederico, that part of the code is not necessary. Thanks.