3

I'm creating a webshop in Drupal 7 using Commerce but I'm stuck on something. When I'm viewing my product node, I would like to activate 1 of the taxonomy terms of my vocabulary named 'category'. So when I'm viewing a product node which is a book, the menu item of 'Webshop >> Books' needs to be highlighted as 'active'.

I've tried menu_set_active_item but this will override the $_GET['q'] parameter which is not good because it affects the page content. When I use this, the taxonomy term is displayed insted of the node so that's not what I want. I only want to active the item in the menu.

I think the way to go is using menu_set_active_trail or menu_tree_set_path but I can't get it working. Maybe someone can show me an example? Maybe I'm only using the wrong hook?

PS: I'm using menu_block to render the menus.

Jeff Maes
  • 707
  • 8
  • 13

1 Answers1

2

Okay, I got it working.

The tricky thing was that the function menu_tree_set_path() will become available in Drupal 7.9... Since I only had 7.8 (the latest official release) it was not working. I was able to update to 7.x-dev because I was still developing and that solved my problem.

So, what's the right way to do it with Drupal 7.9 and above?

/*
 * Implements of hook_node_view()
 */
function MYMODULE_node_view($node, $view_mode, $langcode) {
  menu_tree_set_path('main-menu', 'taxonomy/term/1');
}

For more info, please visit http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_tree_set_path/7

Jeff Maes
  • 707
  • 8
  • 13