Menu link plugins should provide a way for the link to be conditionally hidden

Created on 5 May 2016, about 9 years ago
Updated 2 June 2025, about 1 month ago

AFAICT, there's no way for a menu link plugin to cause the menu link not to appear.

There is MenuLinkInterface::isEnabled(), but returning FALSE from that causes the menu link itself to become disabled.

I've also tried returning either '' or NULL from getRouteName(), but that causes a routing crash. There's route '<none>' but that creates a link to the current page.

At this point the only thing I can see to do is to create a custom route which always denies access, and return that route name.

Use case is that I am writing a custom menu link plugin to show a user's group. If the user has no group memberships, then the link should not show.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

menu system

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024