Module Development

Create Dynamic Menu Links for Drupal 8, 9, 10, and 11

Learn how to generate menu links dynamically with plugin derivatives in a custom module. This tutorial walks through creating a single base menu link plugin definition and a deriver class that expands that definition into one menu link per content entity. The code will automatically generate links for all published basic pages, placing dynamic menu links in the main menu.

By the end of this tutorial, you should be able to:

  • Understand which files you need in order to define menu link plugin derivatives, also known as dynamic menu links
  • Create the necessary code to define menu link plugin derivatives for an example use case