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

mdupont’s picture

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

Features requests have to go against 8x-dev then be backported.

mdupont’s picture

Issue tags: -menu, -hierarchy, -hooks (duplicate), -menu columns

Cleaning useless tags

alex.skrypnyk’s picture

Just bump this until it is not too late.

alex.skrypnyk’s picture

Issue summary: View changes

Fixed some wording

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Active » Fixed

I doubt we really still need that

Status: Fixed » Closed (fixed)

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