Problem/Motivation
If there are N menu links that link to the same path, and that path is active, then each of them get N active classes added.
Proposed resolution
Ensure we find links with the active paths *once*, and then handle the <front> special case *once*. Hence reducing the maximum number of loop iterations to two, instead of N.
Remaining tasks
- Review
User interface changes
None
API changes
None
Original report by @cmatter
Multiple Menulinks to Frontpage make a lot of class atributes "active" only when you are not logged in.
<a href="/" data-drupal-link-system-path="<front>" class="active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active active">Abo</a>
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 2412241-14.patch | 4.23 KB | idebr |
| #14 | interdiff-14-9.txt | 1.92 KB | idebr |
| #14 | 2412241-14.fail_.patch | 965 bytes | idebr |
| #12 | 2412241-9-after.png | 9.78 KB | idebr |
| #12 | 2412241-9-before.png | 10.02 KB | idebr |
Comments
Comment #1
cmatter commentedComment #2
idebr commentedHeh, that is hilarious :)
Added a fix that checks if the class has been added before. I wonder though why each link gets processed multiple times.
Markup before:
Markup after:
Comment #3
berdirWe need some tests for this, also wondering if there would be a better way to manage those classes than a string, might make this easier?
Comment #4
wim leersTests, and a better fix, that fixes the performance problem that this uncovered, and which the patch in #2 didn't address. No interdiff, because different patch.
Updated IS, to clarify the problem, and the solution in this patch.
Comment #5
wim leersOh, and if that patch is confusing:
$type_matchwas never used in HEAD; hence I only remove it without removing its usages: there were no usages :). I suspect I actually originally planned to do something similar to #4, but then forgot, and nobody noticed and it got committed anyway.Comment #7
wim leersReuploading the #4 patch, because testbot failed to detect it…
Comment #9
wim leers#4's test was fine, but its implementation changes were utterly wrong. This should be much better.
Comment #11
wim leersI uploaded them in the wrong order, but the test result speaks for itself. Back to NR.
Comment #12
idebr commentedThe updated patch works as advertised, the issue summary update correctly reflects the content of the patch and the feedback of Berdir in #3 has been addressed. Setting this to RTBC.
Markup before:
Markup after:
Comment #13
alexpottThis line reads really weird because if the class has the active class
$is_activeequalsFALSE. I think we should change the variable name to$add_active. Also I think we should store the result of$node->getAttribute('class')in a variable since we have to do this again later.Comment #14
idebr commentedThanks for the feedback, alexpott. I have updated the patch accordingly.
Comment #16
berdirI think that addresses @alexpott's feedback correctly, agreed that $add_active is a better name.
Comment #17
wim leers+1
Comment #18
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed a5bbb06 and pushed to 8.0.x. Thanks!