You are here

function menu_example_menu_alter in Examples for Developers 7

Same name and namespace in other branches
  1. 6 menu_example/menu_example.module \menu_example_menu_alter()

Implements hook_menu_alter().

Changes the path 'examples/menu_example/menu_original_path' to 'examples/menu_example/menu_altered_path'. Changes the title callback of the 'user/UID' menu item.

Change the path 'examples/menu_example/menu_original_path' to 'examples/menu_example/menu_altered_path'. This change will prevent the page from appearing at the original path (since the item is being unset). You will need to go to examples/menu_example/menu_altered_path manually to see the page.

Remember that hook_menu_alter() only runs at menu_rebuild() time, not every time the page is built, so this typically happens only at cache clear time.

The $items argument is the complete list of menu router items ready to be written to the menu_router table.

Related topics

File

menu_example/menu_example.module, line 454
Module file for menu_example.

Code

function menu_example_menu_alter(&$items) {
  if (!empty($items['examples/menu_example/menu_original_path'])) {
    $items['examples/menu_example/menu_altered_path'] = $items['examples/menu_example/menu_original_path'];
    $items['examples/menu_example/menu_altered_path']['title'] = 'Menu item altered by hook_menu_alter()';
    unset($items['examples/menu_example/menu_original_path']);
  }

  // Here we will change the title callback to our own function, changing the
  // 'user' link from the traditional to always being "username's account".
  if (!empty($items['user/%user'])) {
    $items['user/%user']['title callback'] = 'menu_example_user_page_title';
  }
}