Currently, we are adding an anchor before comments for the fragment identifier anchor point (e.g., "node/41#comment-42").
<a id="comment-42"></a>
<div class="comment">
<div>comment contents</div>
</div>
I would like to see the id placed on the actual comment container for a couple of reasons.
<div id="comment-42" class="comment">
<div>comment contents</div>
</div>
1. It is more symantically accurate. Having the id on an empty anchor doesn't "identify" anything.
2. It allows increased styling options. For example, there is a proposed CSS3 pseudo class ":target" which selects the fragment identified by the fragment identifier in the document URI.
http://www.w3.org/TR/css3-selectors/#target-pseudo
Comments
Comment #1
Jaza commentedThis looks good. +1 as long as anchors pointing to DIVs (rather than other A's) works in all major browsers - and I believe it does. Moving to 6.x-dev queue.
Comment #2
catchsetting back to active now everything is .tpl.php-ified, not sure if this is still valid at all.
Comment #3
dpearcefl commentedIs this issue still needed in current D6?
Comment #4
anybody+1 here, the same problem is existing for Drupal 7, which should be more interesting. I hope the problem will NOT exist in Drupal 8 (or I will cry ;))
The problem is that there is absolutely NO CHANCE to alter the output because all the HTML gets bashed into the #prefix value together with the intendation, 'new' info, etc.!
This is really important and the current solution is a bit crappy :)
You can find the code in comment.module, line 955:
I'd suggest to add this kind of prefixes to a tpl file to make it better editable.
Thanks a lot.
Comment #5
dcam commentedThis is still the case in D8.
Comment #6
gargsuchi commentedHere is a patch which fixes it for D8. Against 8.0.1
Comment #7
jonathanshawChanged extension to .patch so that testbot will pick it up.
Comment #8
jonathanshawComment #11
gargsuchi commentedReuploading after applying a fix.
Comment #12
gargsuchi commentedRemoved
Comment #14
gargsuchi commentedTrying a git patch upload.
Comment #15
jonathanshawStatus must be set to Needs review to trigger testbot
Comment #17
jonathanshawMultiple test fails. May not be a problem with the patch, maybe more that these tests use a method for detecting a comment exists which is disrupted by this patch, hence tests need adjusting.
Comment #18
gargsuchi commentedBump! Can someone RTBC this?
Comment #19
jonathanshawThe test fails need to be addressed before the patch can be committed.
Comment #20
vprocessor commentedComment #22
vprocessor commentedPlease, don't check it, because only diff there
Comment #23
vprocessor commentedComment #24
vprocessor commentedComment #25
vprocessor commentedComment #26
vprocessor commentedHi all, there is interdiff & wip patch: todo some core templates and fixed tests by this log https://www.drupal.org/pift-ci-job/132672
Comment #27
vprocessor commentedComment #29
andypostinteresting...
we can't change templates here
but can add "ID" via preprocess
Comment #30
vprocessor commentedComment #31
andypostsuppose that should be like that
Comment #32
vprocessor commentedComment #37
duaelfrThanks for working on this issue!
According to WCAG 2.0 rule 2.4.4 Link Purpose (In Context), we should not have links without any text or title. This change seem to me really important to clean markup and improve accessibility.
A lot of tests have moved during the last 2 years so this patch needs to be rerolled. Given the patch is easy, I'm tagging this issue as Novice to help newcomers to find something to start with.
Comment #38
ilya.no commentedHi! Attaching reroll and interdiff.
Comment #41
duaelfrSimple reroll after CommentPagerTest has been converted to BrowserTestBase in #2809467: Convert \Drupal\comment\Tests\CommentPagerTest to BrowserTestBase.
Comment #43
andypost@DuaelFr your patch somehow affects composer files, please remove this hunks
Comment #44
duaelfrSometimes I just want to slap myself ;)
Thank you for your awareness
Comment #45
jonathanshawThis looks good.
Comment #47
alexpottThis change should have a change record as the change shows tests are often affected and we're changing markup - which is allowed but documenting it is good.
Comment #48
jonathanshawDraft CR created.
https://www.drupal.org/node/3020137
Comment #49
lauriiiWe should ensure that the id is unique by running this through
Drupal\Component\Utility\Html::getUniqueId.Comment #50
alexpott@lauriii I'm not sure about that - we should these in anchor links elsewhere on the page - I think it is up to the user not to output the comment twice on the same page.
Comment #51
alexpott@lauriii Also as that is more of a change - ie. we don't currently run it through that method - how about a follow-up to discuss all the ramifications of that?
Comment #52
lauriiiSure, I'm fine with that 👍
Comment #53
alexpottOpened #3020394: Investigate using Html::getUniqueId() on comment-ID identifiers
Comment #54
alexpottComment #55
idebr commented@lauriii in #49 has a points this might introduce invalid markup. Alternatively, we could use the
nameattribute instead of theidattribute for identical behavior but without the duplicate id attribute potential.Comment #56
duaelfrThe name attribute is only allowed on form elements so that's not suitable for this usage.
We need these ids to be accurate because it's needed to build anchored links to the comments.
As the first call to
Drupal\Component\Utility\Html::getUniqueIdreturns an unmodified id, it'd be fine to me to use it to prevent potential multiple comments outputs in the same page to break the ids uniqueness while preserving linkability.Comment #57
jonathanshawAs I understand it, the discussion in #55 and #56 would be better on #3020394: Investigate using Html::getUniqueId() on comment-ID identifiers, as the present patch does not worsen this problem and therefore will not address it.
Comment #59
lauriiiLooks good! Moving the id to the parent element is a small risk because someone could have used it for targeting CSS or JavaScript but since it isn't generally good practice to use ids for doing that, I'm fine with making this change. Committed 69b99ec and pushed to 8.7.x. Thanks!