Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
<nolink>
and <none>
are two routes provided by core that can be used to create empty links, without urls. This can be done through the menu system by creating a menu item with a link route:<nolink>
.
However, because these urls are empty, Drupal currently considers these link to be going to the front page.
This means two things:
- The links are generated with
"data-drupal-link-system-path=<front>"
- The links are generated with
class="is-active"
when on the homepage.
What is the expected behaviour? Nolinks should not contain either data-drupal-link-system-path
or is-active
on any page.
Comment | File | Size | Author |
---|---|---|---|
#22 | Screen Shot 2018-05-10 at 10.33.28.png | 339.72 KB | Leon Kessler |
#22 | Screen Shot 2018-05-10 at 10.32.36.png | 289.45 KB | Leon Kessler |
#19 | 2838351-interdiff-12-19.txt | 3.14 KB | Leon Kessler |
#19 | links_with_no_path_get-2838351-19-TEST-ONLY.patch | 1.98 KB | Leon Kessler |
#19 | links_with_no_path_get-2838351-19.patch | 2.95 KB | Leon Kessler |
Comments
Comment #2
Leon Kessler CreditAttribution: Leon Kessler commentedPatch which adds a simple check that the link isn't
<nolink>
when generating thedata-drupal-link-system-path
. This also fixes the active class issue.Added
set_active_class
in the test. This fails with LinkGenerator.php in it's previous state, and passes when the update is applied.Comment #3
Leon Kessler CreditAttribution: Leon Kessler commentedComment #4
Leon Kessler CreditAttribution: Leon Kessler commentedComment #5
Leon Kessler CreditAttribution: Leon Kessler at Mirum Agency commentedComment #6
andypostthe generated markup need tests
Comment #7
Leon Kessler CreditAttribution: Leon Kessler at Mirum Agency commented@andypost the existing test for markup
$this->assertSame('<span>Test</span>', (string) $result);
is still correct...
By adding
$url->setOption('set_active_class', TRUE);
to the test, we are ensuring that this does not affect the output.Comment #8
andypostI it correct then why it does not fail?
the issue supposed to be a bug then better to have some fail.patch to show that bug exists and then patch that fixes
Comment #9
Leon Kessler CreditAttribution: Leon Kessler at Mirum Agency commentedAh okay sure, here's the patch that will fail (this contains the updated test, but without the update to LinkGenerator.php
Comment #11
JeroenTComment #12
Leon Kessler CreditAttribution: Leon Kessler at Mirum Agency commentedFound another case where the is-active class is set incorrectly. When using
<nolink>
(which can happen if you set a menu item to link to a fragment#
).I've uploaded a new patch an interdiff, but I think this probably needs a bit more though (there are perhaps other types of links where this issue happens). Also the tests should now be expanded to cover these cases.
Comment #16
FiNeX CreditAttribution: FiNeX as a volunteer commentedHi, I'm also experiencing this bug using latest Drupal 8.5.1. Are the patches safe enough to be applied? Thanks!
Comment #17
Leon Kessler CreditAttribution: Leon Kessler commentedHi @FiNeX
Yes, it may well need a re-roll, but should be safe (we had the patch running on a production site with no issues).
I should have sometime to take a look at addressing issues I posted in my previous comment soon.
Comment #18
Eyal ShalevThe patch in #12 works on the latest branch, and it has been over a year since submitted - so I'm moving this issue to needs review.
Comment #19
Leon Kessler CreditAttribution: Leon Kessler commentedI have gone over the comments that I raised back in #12.
<nolink>
and<none>
are the only routes I can find which are effected by this issue (in core).I have added an additional test for
<none>
routes.And I've also modified
LinkGenerator::generate
so that rather than checking the route name, we simply check if the url is empty. To me this makes more sense, as it should cover other possible similar empty routes.Comment #21
Leon Kessler CreditAttribution: Leon Kessler as a volunteer commentedTests passed, setting back to needs review.
Comment #22
Leon Kessler CreditAttribution: Leon Kessler as a volunteer commentedUpdating issue summary, adding screengrabs.
Comment #23
Eyal ShalevLeon, Wouldn't a link to the front-page have an empty url?
Comment #24
Leon Kessler CreditAttribution: Leon Kessler as a volunteer commentedThat's already covered in the preceding conditional:
Comment #26
LaravZ CreditAttribution: LaravZ commentedThe patch was applied cleanly to my existing 8.5.6 installation and a new 8.7.x installation, and the data-drupal-link-system-path en class="is-active" elements were removed. The system path now no longer defaults to but to , which seems to me to be more desirable. Do you reckon it would be desirable to mention above the code that it now defaults to ?
Comment #27
Leon Kessler CreditAttribution: Leon Kessler as a volunteer commented@LaravZ, in terms of code commenting, I didn't think it was necessary to add anything here. The
is self-explanatory (and I think it's always preferable for code that documents itself).
However, Eyal's version (on https://www.drupal.org/project/drupal/issues/2963523) is more explicit, and as such includes a comment:
I would say my approach is simpler, and would cover other possible routes that are empty. But happy to go with Eyal's approach if that's what everyone favours.
Comment #28
LaravZ CreditAttribution: LaravZ commentedNah, I like simple approaches as long as they suffice. And I suppose the code alteration can be traced back to this issue, so I am personally fine with not adding any additional comments.
Comment #29
LaravZ CreditAttribution: LaravZ commentedComment #30
alexpottBefore the
data-drupal-link-system-path
would always be set to something. No it is not. I think this is correct because there is no system path so that's good. But I think we need to create a change record to document the change. There's a link to add a change record above the related issues list.Comment #31
LaravZ CreditAttribution: LaravZ commentedAlright, I've added a change record: https://www.drupal.org/node/3000819
Comment #32
alexpott@LaravZ thanks for that. The change record is to tell users about the effects of the change not to rebuild the patch. So the important information here is that links with the route nolink and none will no longer have a data-drupal-link-system-path attribute. The nitty gritty of the patch is not so important.
Comment #33
LaravZ CreditAttribution: LaravZ commentedAlright, I've replaced the code in the before and after to regular text in order to properly explain the changes. Thanks, @alexpott!
Comment #34
alexpott@LaravZ I've edited the change record to only focus on the important information. So people know about the change that might affect their site and not anything extraneous.
Comment #35
LaravZ CreditAttribution: LaravZ commentedMakes sense, do we need to do anything else before we can reset the status to Reviewed & tested by the community?
Comment #36
alexpott@LaravZ I don't think so. As a committer it's best that I don't rtbc patches myself.
Comment #37
LaravZ CreditAttribution: LaravZ commentedComment #38
alexpottCommitted 8e67805 and pushed to 8.7.x. Thanks!
I've only committed this to 8.7.x because of the changes to markup which are not API per se but might in very rare cases affect a real site (or maybe a workaround put in place to overcome this issue). Only committing to 8.7.x gives people time to discover we've fixed this and adapt accordingly.
Comment #40
MrPaulDriver CreditAttribution: MrPaulDriver commentedWill this be back ported to 8.6 ?
Comment #41
alexpott@MrPaulDriver see #38
Comment #43
phelix CreditAttribution: phelix commentedI am running Drupal 9 and using
<front>#anchorName
is adding this data element and class on every link on the menu. Is there a way to fix this?