Drupal 8 Menu Item Extras Module
Share with Others
The Drupal 8 Menu Item Extras module brings the power of fields to the Drupal menu system. By default, menu items are not fieldable. This means if you needed to add additional information to a menu item, you can’t do it with out of the box Drupal.
This Menu Item Extras module makes it easy to add fields to your menu items as well as customize the view and form display (just like you can on other entities). By using this module you can do things such as:
- Create a megamenu drop down
- Add an image field to associate with a menu item
- Configure different menu items to use different display modes
Download the Menu Item Extras module like you would any other Drupal module. You can download it with Composer using the following command:
composer require drupal/menu_item_extras
Install the Menu Item Extras module. The module also provides a Demo module that can be used to see some examples of a menu with fields and display modes configured. In this case, we will just look at the base Menu Item Extras module.
Navigate to Structure > Menus > Main Navigation. The first thing you should notice is that there are additional links to Manage fields, Manage form display, Manage display, and View mode settings. This is very similar to what you have probably used on other entity types.
If you need to store any additional data for a menu link, you can do this on the Manage fields page. One potential use of this is to add an image field:
You can then manage the way this is displayed on the menu link add/edit form:
You can also control how this menu item is displayed:
If you navigate to Structure > Display modes > View modes you can add additional view modes for menu items. In this example, I created a new view mode for Custom menu links. I called the view mode Image Link.
You can now navigate back to Structure > Menus > Main Navigation and go to Manage display. In the Custom Display Settings section, you can enable the Image Link view mode and configure the display settings for the Default links and the Image Link view mode displays.
You can now navigate to the View Modes Settings tab and select what view mode to use for each link in your menu.
This additional flexibility allows you to do a lot with your menu items. You could use this to build out a customized mega menu (this would require additional theme and template development). You could also use this to customize the display of menu items (perhaps by adding icons next to menu links, adding additional menu link descriptions, and more. The module provides you the site building tools to customize your menu items, now it’s up to you to decide how you want to use it!