function menu_example_menu_alter

Same name in other branches
  1. 7.x-1.x menu_example/menu_example.module \menu_example_menu_alter()

Implements hook_menu_alter().

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

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.

Parameters

$items: 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 391

Code

function menu_example_menu_alter(&$items) {
    // Change the path 'menu_example/menu_original_path' to '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 menu_example/menu_altered_path manually to see the page.
    if (!empty($items['menu_example/menu_original_path'])) {
        $items['menu_example/menu_altered_path'] = $items['menu_example/menu_original_path'];
        $items['menu_example/menu_altered_path']['title'] = 'Menu item altered by hook_menu_alter()';
        unset($items['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_uid_optional'])) {
        $items['user/%user_uid_optional']['title callback'] = 'menu_example_user_page_title';
    }
}