Problem/Motivation
When using route:<nolink>
the LinkGenerator
class creates a <span>
tag instead of an anchor tag which makes sense for certain scenarios, but it is not accessible if the non-link will have interactivity added to it via JavaScript. It would be beneficial to have the option to use the semantically-correct <button>
HTML tag here for such cases.
Proposed resolution
Since the only way to modify the HTML tag is through a special route (demonstrated by route:<nolink>
), it would appear a new special route is required for this use case: route:<button>
Remaining tasks
User interface changes
API changes
None: If someone defined a <button>
route it would break, but that is unlikely. Also, when route:<nolink>
was added there was not a corresponding change record.
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#31 | allow-button-tag-in-linkgenerator-2999549-31.patch | 5.17 KB | mtift |
#31 | interdiff-28-31.txt | 2.3 KB | mtift |
#7 | allow-button-tag-in-linkgenerator-2999549-7.patch | 3.23 KB | Daniel Korte |
Comments
Comment #2
Daniel KorteComment #3
Daniel KorteComment #4
Daniel KorteAdded
type="button"
since the default for a button istype="submit"
which causes unexpected behavior when editing a menu.Comment #5
Daniel KorteComment #7
Daniel KorteComment #8
mtiftWe need this functionality, too. Rerolling...
Comment #10
mtiftI didn't resolve that conflict properly. Trying again.
Comment #12
mtiftFixing a typo
Comment #13
mherchelVerified that the latest patch in #12 works.
Comment #14
tim.plunkettFixing tags
Comment #16
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commented+1 for this feature request. The motivation is well described in the issue summary. It's a widely applicable feature for mega-menus, tree-style sidebar menus, login forms presenting login forms on dialogs.
This would benefit from a change record. That should be drafted before RTBC.
The patch looks straightforward enough, but I haven't managed to test this yet. I'm relying on simplytest.me today, and got errors. I've queued another test for the patch in #12.
Comment #17
mherchelDraft change record created at https://www.drupal.org/node/3053689
Comment #18
m4oliveiCode looks great.
Also tried it out on a stock Umami install by adding a menu link to the main menu. I set the link to
route:<button>
and it did indeed show up as a button with the markup:Comment #19
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedQueued tests against 8.8.x
Comment #20
mherchel@andrewmacpherson are we supposed to see results posted in this issue? I'm not sure how this works.
Comment #21
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commented@mherchel - the test results are noted next to the patch itself. You can see the result in comment #12 - it passes against 8.8.x
Comment #22
alexpottI'm not convinced we've using the correct namespace here - but it is the namespace we've used for \Drupal\Core\GeneratedLink and \Drupal\Core\GeneratedNoLink - I think we should consider moving these to either
Drupal\Core\Routing
,Drupal\Core\Menu
,Drupal\Core\Utility
(along side LinkGenerator) or somewhere new - let's open a follow-up for that.One thing I was thinking about is how this relates to and more importantly does not relate to \Drupal\Core\Render\Element\Button and what confusion it could introduce. I think the description here might need to go into that. Or at least mention that this is not for generating buttons for forms but for putting a button in a list of links such as a multi-level menu.
Comment #23
mtiftItem 1 (from #22) should be resolved with https://www.drupal.org/project/drupal/issues/3074978. Next I'll work on item 2.
Comment #24
mtiftHere's the updated patch that addresses item 2 from #22
Comment #25
mherchelIssue and comment look good to me. Thanks @mtift!
Comment #26
catch<button>
generated from the<button>
route is very confusing to read. First I thought it was a mistake in the patch, but reading GeneratedNoLink it's correct, but still confusing. I tried to think of alternative wording but struggled a bit.Comment #27
larowlanthis is getting unwieldy now, can we add a protected method the elements after this that are common and return early instead of stacking up the elseifs
e.g. lines 181-187 of HEAD
Would become a new method, something like doGenerate
Then inside the first if we'd do
Then the next two elseifs (with this patch) become just ifs that also return
and the final else is not needed, as by that stage the others have returned.
Comment #28
mtiftComment #29
mtiftSounds good.
Comment #30
mtiftThat last patch doesn't work. Missing $variables and perhaps more.
Comment #31
mtiftLet's try this
Comment #32
mherchelVerified #31 patch applies and is working correctly!
Comment #34
eeyorrAny updates on when this will be committed?
Comment #35
eeyorrIs this going to be committed???
Comment #36
mherchel@eeyorr At the earliest this will go in Drupal 9.1 (probably early 2021).
Currently the core committers are trying to work out all of the deprecations in Drupal 9.0 to get that out of the door.
I'm planning on going to Drupal Dev Days in about a month. Assume there are some core committers there, I'm going to bug them :P
Comment #37
eeyorr@mherchel, thanks for the update!
Comment #38
alexpott#26 hasn't been addressed but I can't think of a better wording either. @mherchel actually we can commit this to 8.9.x and 9.0.x now. Nothing is frozen - yes issues like this are not a priority but this is still a good thing to add to core that's very difficult for contrib to do.
Committed and pushed 8ed835c0bc to 9.0.x and 485db38e54 to 8.9.x. Thanks!
Fixed coding standards on commit.
Comment #42
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedThe change record for this issue is still at draft status. Should it be published?