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

kjay’s picture

I 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?

grendzy’s picture

Status: Active » Closed (duplicate)

Yes, 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.

glass.dimly’s picture

We found some code in ctools that fixed this problem for us:
http://drupal.org/node/791862

glass.dimly’s picture

FYI the code was

<?php
function your_module_init() {
	if (menu_get_active_menu_name() == 'navigation') {
		$item = menu_get_item();
		$mlink = db_fetch_object(db_query("SELECT * FROM {menu_links} WHERE link_path = '%s'", $item['href']));
		if ($mlink && isset($mlink->menu_name)) {
			menu_set_active_menu_name($mlink->menu_name);
		}
	}
	$request = request_uri();
	$full_path = explode ( '/', drupal_get_path_alias($request));
}
?>
jm.federico’s picture

Thanks for that code.
One question though, what are the last two lines for?

    $request = request_uri();
    $full_path = explode ( '/', drupal_get_path_alias($request));

Thanks again.

jck4’s picture

Thanks 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!

glass.dimly’s picture

You 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.