Drupal's Menu API, menu links, and local actions provide tools for defining and managing navigational elements and contextual actions, facilitating the creation of intuitive and organized site structures and user interfaces.
This course covers the structure and syntax of the YAML files required to define menu links, menu items, and local tasks, as well as practical examples of how to implement them. You will also learn how to use these links to enhance site navigation and user experience by providing quick access to important actions and tasks.
Key topics
- Overview of menu links in a module
- Adding a menu link in a module
- Adding an action link in a module
- Adding a contextual link in a module
- Adding a local task link in a module
- Understanding the differences between menu links, action links, contextual links, and local task links
- Practical examples and best practices for implementing links in Drupal modules
Drupal provides module developers several different methods for creating the different types of links we see on a typical page. In this tutorial we'll see how these different types of links relate to each other, and when you might want to make use of them.
In this tutorial we'll provide an overview of the following concepts:
- Menu links
- Action links
- Local tasks
- Contextual links
In this tutorial we will learn how to add menu links using a custom Drupal module. We will also look at the options available for configuring our new menu link. Lastly, we'll learn about using hook_menu_links_discovered_alter()
that can be used to add new menu links, or alter the behavior of existing ones.
Modules can provide action links to make common operations more readily available within a particular context. For example, a site administrator visiting the content management page may be interested in adding content. If you've ever noticed the Add content button on this page, that's an example of an action link. In this tutorial we'll take a look at how custom modules can provide these action links to make it easier for users to interact with our site.
Contextual links provide yet another method for Drupal module developers to add helpful links for site administrators to quickly navigate to commonly used tasks. In this tutorial we'll learn how to implement and render contextual links from a custom module. We will also look at a pair of alter hooks that can be used to tweak existing contextual links.
Local task links are the tabs you see when logged in as an administrator viewing a node on a Drupal site. In this tutorial we'll take a look at how local tasks are added within a custom module. We'll also see how to alter local tasks provided by other modules via hook_menu_local_tasks_alter()
.