I've bumped into an unfriendly wall with upgrading og and devel to D6. We no longer let menu items have dynamic querystrings. OG needs this to add the current group ID to the node/add links in its block. Devel needs to add a drupal_get_destination() on its 'empty cache' menu link so that you can be redircted to the same page after emptying cache.

In D5, you could do this:


function hook_menu($may_cache) {
  if ($may_cache) {

  }
  else {
    $items[] = array('path' => 'foo', 'query' => drupal_get_destination());
  }
}

In D6, I propose that a module do this (for example):


/**
 * An implementation of hook_menu_link_alter(). Flag this link as needing alter at display time.
 * See devel_translated_menu_link_alter().
 *
 **/
function devel_menu_link_alter(&$item) {
  if ($item['link_path'] == 'devel/cache/clear') {
    $item['options']['alter'] = TRUE;
  }
}

/**
 * An implementation of hook_translated_menu_item_alter(). Append dynamic 
 * querystring 'destination' to several of our own menu items.
 * 
 **/
function devel_translated_menu_link_alter(&$item) {
  if ($item['href'] == 'devel/cache/clear') {
    $item['localized_options']['query'] = drupal_get_destination();
  }
}

In current D6, there is simply no way to do this (I confirmed with chx and pwolanin), and thus we have a regression. This small patch adds an alter hook in menu.inc for this purpose. We only run the alter hook on menu items that have flagged themselves as needing altering. This is a performance optimization.

The code above has actually been committed to devel HEAD so feel free to download it in order to exercise this small patch. I will obviously remove this code from devel if this patch is not committed to D6.

I apologize for finding this regression so late in the release cycle. I did port devel a long time ago, but didn't do a "full embrace" of new menu system until now. I hope folks will find the added drupal_alter() call to be safe and incapable of harm.

CommentFileSizeAuthor
mw.patch1 KBmoshe weitzman

Comments

chx’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

SO nice trick -- does not affect anything ported , has no performance implications and SO badly needed.

moshe weitzman’s picture

chx helped me simplify my devel implementation so i only implement the second of the functions above. you can see devel_menu() in HEAD if you care ... the patch remains unchanged.

gábor hojtsy’s picture

Version: 6.x-dev » 7.x-dev

Oh, well. Committed to 6.x. RTBC for 7.x

pwolanin’s picture

fabulous - I spent a long time talking through this with moshe, and I think this is a good solution

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to Drupal 7.

pwolanin’s picture

docs in CVS updated: http://drupal.org/node/219542

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.