In this tutorial we will learn how to add items to the menu system from within a custom module. We will also look at the options available for configuring our new menu item. Lastly, we'll learn about using
hook_menu_links_discovered_alter() that can be used to add new menu items, or alter the behavior of existing ones.
Drupal's menu system allows users to create as many separate menus as they need throughout their site. Links can be created to both external sites and internal pieces of content. The site administration interface gives users (with sufficient permissions) the ability to organize and sort these links within their respective menus. The API provided by the menu system gives developers the ability to interact with and alter menu links. The API also includes a mechanism to provide menu links from within custom modules.
- Create several menus for use (and display) in various locations throughout a site
- Add a link to a menu from within a custom module
- Understand how existing menu items can be altered
The Drupal menu system has been quite stable, and although our coverage isn't complete at this point the resources cited are unlikely to change rapidly.
We are still filling out our Drupal 8 library and this page will be updated with new tutorials as they are created.
This tutorial is part of our Module Developer in Drupal 7 series. Several of the tutorials that follow this one walk through some of the more advanced techniques for working with the menu system.
This video provides a high level overview for the site builder or administrator about the main components that make up a Drupal site (including the menu system).