Setting menu trails by path - hook question
Hi, I am trying to write a module that would set the active menu trail depending on the path. E.g. if the current path is /a/b/c and there is no menu item with the path /a/b/c, then the menu item with the path /a/b (and its parents) will be set as active. The only problem so far is that the code does not work if I put it in hook_menu(!$may_cache). I've tried setting the weight of the module to a higher value, but to no result. This is the sample code I am trying out: function pathtrails_menu($may_cache) { if (!$may_cache) { $location = array(); $location[] = menu_get_item(46); $location[] = array('path' => drupal_get_normal_path($_GET['q']), 'title' => drupal_get_title()); menu_set_location($location); } } The same code works just fine if I put it into another module's page callback function. I guess, I could put the code into hook_nodeapi (just like menu trails module does), but I want this to work for all pages, not just nodes. Should I be using a different hook? Am I missing something else? Maybe there already is a solution to this problem? Thanks in advance, Domas
Domas Monkus wrote:
Hi, I am trying to write a module that would set the active menu trail depending on the path.
you might want to have a look at http://drupal.org/project/menutrails
you might want to have a look at http://drupal.org/project/menutrails
I have. It sets the active menu trail for nodes only. And it uses hook_nodeapi to do that. I have mentioned this in my email. This won't let me set the active path for every page (even module-generated ones). Domas
Try putting print statements in menu_set_location and menu_set_active_item (and possibly other places) to see if some module is calling this _after_ you call it. And noone should be calling menu_set_location without reading: http://www.angrydonuts.com/menu_set_location_can_eat_my_sho On Tuesday 01 April 2008, Domas Monkus wrote: [snip]
The same code works just fine if I put it into another module's page callback function. I guess, I could put the code into hook_nodeapi (just like menu trails module does), but I want this to work for all pages, not just nodes.
Should I be using a different hook? Am I missing something else? Maybe there already is a solution to this problem?
And noone should be calling menu_set_location without reading: http://www.angrydonuts.com/menu_set_location_can_eat_my_sho I've figured it out. It appers menu_block_split was to blame. It uset menu_get_active_nontask_item to find out which second level menu to expand. Had to change it to use _menu_get_trail.
Thanks for the help, Domas
participants (3)
-
Dave Cohen -
Domas Monkus -
Gregory 'guardian' Pakosz