[development] Setting menu trails by path - hook question

Domas Monkus domas.m at gmail.com
Tue Apr 1 08:30:28 UTC 2008


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


More information about the development mailing list