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.
| Comment | File | Size | Author |
|---|---|---|---|
| mw.patch | 1 KB | moshe weitzman |
Comments
Comment #1
chx commentedSO nice trick -- does not affect anything ported , has no performance implications and SO badly needed.
Comment #2
moshe weitzman commentedchx 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.
Comment #3
gábor hojtsyOh, well. Committed to 6.x. RTBC for 7.x
Comment #4
pwolanin commentedfabulous - I spent a long time talking through this with moshe, and I think this is a good solution
Comment #5
dries commentedCommitted to Drupal 7.
Comment #6
pwolanin commenteddocs in CVS updated: http://drupal.org/node/219542
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.