Problem/Motivation
When adding a Menu Item, it is possible to add special items like <nolink> or <button>
According to Menu Link form:
Enter <nolink> to display link text only. Enter <button> to display keyboard-accessible link text only.
Current navigation twig template structure does not respect these items and render them as links whose href is empty, having a different behavior than the expected one.
Attaching screenshots of the same menu as part of navigation or as a block to show the differences:


Steps to reproduce
- Install a Drupal site and enable navigation
- Edit any of the menus included in the navigation bar
- Add menu links whose Link field value is <nolink> or <button>
- Confirm that those items are shown as empty links instead of the expected HTML markup
Proposed resolution
Update navigation twig templates to respect the special menu items behavior.
Checked how menu.html.twig works and it seems this piece of code generates the expected markup:
{{
link(
item.title,
item.url,
item.attributes.removeClass(item_classes).addClass(link_classes)
)
}}Could be worth to explore how it works and try to reuse or replicate its behavior.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3447837-nr-bot.txt | 4.09 KB | needs-review-queue-bot |
| #12 | Monosnap Edit menu Administration | Drush Site-Install 2024-05-24 15-55-58.png | 192.88 KB | m4olivei |
| #8 | Umami-BeforeMR.png | 37.6 KB | kanchan bhogade |
| #8 | BeforeMR.png | 38.46 KB | kanchan bhogade |
| #8 | Umami-AfterMR.png | 107.03 KB | kanchan bhogade |
Issue fork drupal-3447837
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3447837-special-menu-items
changes, plain diff MR !8117
Comments
Comment #2
plopescComment #3
kostyashupenkoIn progress
Comment #5
kostyashupenkoGood catch.
It's now ready for review.
made also span element not interactable visually (no hover styles). Also added few fixes for forced-colors: active mode
Comment #6
smustgrave commentedCan we had a test case to cover this scenario please
Comment #7
plopescTests added for this new scenario.
Comment #8
kanchan bhogade commentedHi
I've tested MR !8117 on Drupal 11
The MR is applied cleanly...
Special Menu items' empty links in the navigation issue is fixed.
RTBC+1
Adding SS
Comment #9
m4oliveiComment #10
m4oliveiComment #11
smustgrave commentedThanks @plopesc for the quick tests
Coverage appears to be there.
Manual testing I get the same as the issue summary.
Code change appears fine
Comment #12
m4olivei+1 RTBC. I tested locally and it works as you might expect:
Comment #13
finnsky commentedI would like to fix some css and twig here.
Comment #14
m4oliveiI took a crack at breaking the standstill on the one issue. Lets see what we all think.
Comment #15
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #16
finnsky commented@m4olivei
I love that idea. existing twig function isn't really flexible.
Comment #17
finnsky commentedComment #18
finnsky commentedI think it may need change record since we add new function in Drupal Twig here.
Comment #19
finnsky commentedCR: https://www.drupal.org/node/3454916
Comment #20
plopescThank you for pushing this one!
Checked code and found out that new approach is not respecting menu link attributes. Added extra tests to confirm it and avoid overlooking this again.
I don't know if the new approach clears up all the doubts about the use of stateless functions and how to handle the use of menu links in SDC expressed in the original version.
That is a bigger concern that not only affects to navigation, but also to how to render menus in SDC. A follow up issue to address this in a global and consolidated way could be worth here.
Comment #21
m4oliveiI think we're all set on all threads. Tests now passing and ready for a re-review.
Comment #22
finnsky commentedComment #23
plopescMarking as RTBC, we need now the framework manager review for the new Twig function.
Thank you!
Comment #24
nod_Is this made obsolete by #3458215: Migrate Toolbar button to SDC ? In the other MR an item without URL is taken into account.
I'd rather not add another Drupal specific twig function.
Comment #25
smustgrave commentedPer the response in #3458215: Migrate Toolbar button to SDC these appear to be separate.
Comment #26
m4oliveiComment #27
m4oliveiI found a regression with the use of the new link_tag Twig function in Olivero. That obviously weakens the case for it, as navigation would be the single use of it. Added to the hesitation for adding another Twig function, I've removed it and instead taken inspriation from Olivero's template, using the same conditional for our purposes of deriving the HTML tag name from the URL object.
Should be all set now. Hopefully will be easier to get through without the introduction of the Twig function.
Comment #28
m4oliveiAlso note, if we have agreement, @finnsky we can delete the change record.
Comment #29
m4oliveiComment #30
plopescCode looks good to me!
Once we are not adding the new twig function, I believe the frontend framework manager review is not needed anymore.
Comment #31
alexpottI've added a comment on the MR. I think we need to adjust things because we're in a loop and it is possible
item_link_tagwill have a value from a previous iteration of the loop. Also we can use the constants to keep things consistent.Comment #32
plopescCode suggestions applied, MR branch synced with 11.x and tests are green.
I think this one can be marked as RTBC.
Comment #33
alexpottCommitted and pushed 1c67d3b559 to 11.x and 2305dacae3 to 11.0.x and a5a8967cd4 to 10.4.x and 5f44b4b454 to 10.3.x. Thanks!
Backported to 10.3.x as navigation is an experimental module.