Problem/Motivation
Sometimes there is a need to alter menu structure without actually making changes to menu items data.
This maybe requried for theming needs (llke put menu items in columns as implemented in menu_columns at http://drupal.org/sandbox/alex.designworks/1156284).
There is a discussion about this at http://drupal.org/node/1162758
Proposed resolution
Add new hook hook_menu_tree_alter(&$tree, $menu_name) that will allow to pass menu by reference and make any required alterations. This hook will return new altered tree.
For Drupal 6, 1 line addition to includes/menu.inc core file required.
Remaining tasks
Documentation and tests are required if/when hook is added to core.
User interface changes
None
API changes
File includes/menu.inc (Drupal 6)
Before
function menu_tree($menu_name = 'navigation') {
static $menu_output = array();
if (!isset($menu_output[$menu_name])) {
$tree = menu_tree_page_data($menu_name);
$menu_output[$menu_name] = menu_tree_output($tree);
}
return $menu_output[$menu_name];
}
After
function menu_tree($menu_name = 'navigation') {
static $menu_output = array();
if (!isset($menu_output[$menu_name])) {
$tree = menu_tree_page_data($menu_name);
$tree = module_invoke_all('menu_tree_alter',$tree, $menu_name); <-- THIS IS THE LINE WE ADDED
$menu_output[$menu_name] = menu_tree_output($tree);
}
return $menu_output[$menu_name];
}
Comments
Comment #1
mdupontFeatures requests have to go against 8x-dev then be backported.
Comment #2
mdupontCleaning useless tags
Comment #3
alex.skrypnykJust bump this until it is not too late.
Comment #3.0
alex.skrypnykFixed some wording
Comment #5
dawehnerI doubt we really still need that