I've modified menu.inc to allow the the callback argument in menu($path, $title, $callback, $weight) to be an array, where the first element is the function name and the rest are arguments to be passed to said function.

It can still be a string to ensure backward compatibility.

Since the location of the links in the menu structure are dependant on the path... and the path is the only way to pass arguments to the callback (through the arg() function)... you're limited to how you can arrange things in the navigation menu.

I wrote this to allow a custom module I'm working on (navigation.module) to work.

-Skip

CommentFileSizeAuthor
skip.pass-variables-to-menu.patch1.18 KBskip
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

I tried this patch and it works as advertised. is useful, IMO.

moshe weitzman’s picture

For example, the silly wrapper function called aggregator_help_page() could be eliminated with this patch.

Anonymous’s picture

I too found myself in a situation where I wanted a theme function to be the menu callback, and I had to write a wrapper function in order to pass the parameters to theme().

menu('admin/store/transaction/print', t('print transaction'), 'store_invoice', 0, MENU_HIDE);

function store_invoice() {
  return theme('store_invoice', arg(4));
}
JonBob’s picture

This is available in HEAD via the "callback arguments" attribute that can be returned from hook_menu().

Anonymous’s picture