Module Development

Define a Menu Item for Drupal 8, 9, 10, and 11

Drupal's Menu system allows module developers to define navigational links, offering flexibility to site builders for configuration and arrangement. By linking to routes rather than URLs, these links remain functional, even when route definitions change.

In this tutorial, we'll:

  • Create a MODULE_NAME.links.menu.yml file.
  • Define a new menu item link for the /weather page in our anytown module.
  • Configure Drupal to display the link in the primary navigation.

By the end of this tutorial, you'll be able to define new menu item links and integrate them into your site's configuration.

Drupal Module Developer Guide