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.
Reported by #402254: How do we do on XHTML validation?, something is outputting duplicate 'new' IDs in forum listing:
GET http://dev.local/Drupal/Core7/forum/2 returned 200 (9.22 KB).
DOMDocument::loadHTML(): ID new already defined in Entity, line: 96
DOMDocument::loadHTML(): ID new already defined in Entity, line: 108
DOMDocument::loadHTML(): ID new already defined in Entity, line: 120
DOMDocument::loadHTML(): ID new already defined in Entity, line: 132
Comment | File | Size | Author |
---|---|---|---|
#53 | 405238-53.patch | 3.08 KB | amateescu |
#50 | 405238-forum_duplicate_id-rev15.patch | 3.41 KB | brianV |
#50 | Screenshot-1.png | 50.55 KB | brianV |
#46 | 405238-forum_duplicate_id-rev14.patch | 3.46 KB | brianV |
#44 | 405238-forum_duplicate_id-rev13.patch | 3.39 KB | brianV |
Comments
Comment #1
Dave ReidLet's tag all these with 'XHTML validation'
Comment #2
karschsp CreditAttribution: karschsp commentedtagging this for the novice queue. It looks like the problem is in forum-icon.tpl.php.
Comment #3
wretched sinner - saved by grace CreditAttribution: wretched sinner - saved by grace commentedComment #4
brianV CreditAttribution: brianV commentedPatch attached.
Changed
<a id="new">
to:
<a class="new-posts">
The class name was changed to 'new-posts' since the 'new' class is already used in Garland for the 'new' indicators on comments not yet seen by the users.
From Garland's comment.tpl.php:
I don't think this class name change affects any other theming in core.
Comment #5
brianV CreditAttribution: brianV commentedComment #6
Damien Tournoud CreditAttribution: Damien Tournoud commentedI'm wondering: do we need the first of those links to be tagged with
id="new"
, in order to be a target for#new
URL arguments?Comment #7
brianV CreditAttribution: brianV commentedI hadn't thought of that. The module uses the first 'id="new"' as the anchor the browser jumps to.
Since the 'name' attribute is deprecated in XHTML, we need to use an 'id' to jump to with that link.
This means we will need to write code to determine which thread is the first unread thread, and create a link before it to act as the target.
Looking into it further!
Comment #8
brianV CreditAttribution: brianV commentedJust assigning to me, and changing to 'needs work'. I have a pretty good patch on the go that should fix this issue properly. It's just a little more involved than I expected.
Comment #9
brianV CreditAttribution: brianV commentedThis new patch adds
<a id="new"></a>
to only the first new topic in the topic list.Comment #10
Dries CreditAttribution: Dries commentedOr instead of generating id="new", and jumping to that with "#new", we could just link to the proper comment ID?
Comment #11
brianV CreditAttribution: brianV commentedDries,
I suspect you may be thinking of the page displaying a given forum topic along with it's replies. In that context, your suggestion makes sense, but it is an issue for comment.module.
(off-topic)
Just to point out a small problem: with the existing approach, the comment.module only has to calculate the most recent comment when the user visits a node containing new comments. In the usage you suggest, the most recent comment would have to be calculated for every node displayed in forum or node listings in order to generate the correct 'new' link containing the comment id to the latest comment, regardless of whether or not the user actually visits the node. This would be somewhat less efficient from a performance standpoint.
(/offtopic)
That aside, this issue is looking at the forum topic list, which shows a table or forum topics, the number of replies, who created it, and who made the last post.
N.B. The handling in the patch I've written is consistent with that used by comment.module in the same situation. comment.module also places
<a id="new" />
in the first unread comment in the list of comments.Comment #12
Damien Tournoud CreditAttribution: Damien Tournoud commentedNice!
Some remarks:
1.
$is_first_new_topic
should be a boolean. I know that$sticky
is not, but this one comes from the DB2.
Apparently, we don't need to count the new topics, but only to know if we are on the first new topic.
Comment #13
brianV CreditAttribution: brianV commentedOk, I will make another pass at it with these comments in mind.
Comment #14
brianV CreditAttribution: brianV commentedNew version rolled.
$is_new_topic
is now a boolean.$num_new_topics
renamed to$was_first_new_found
and made into boolean to better reflect usage.Relevant code section:
Comment #15
catchDries, being able to link to the correct comment ID instead of #new is the subject of #26966: Fix comment links when paging is used. - there aren't any nice ways to do this with the current state of comment module.
Couple of code style issues with this patch:
All the booleans need to be upper case - TRUE/FALSE.
This should start with a capital letter and end with a full stop.
Otherwise looks great.
Comment #16
brianV CreditAttribution: brianV commentedOops!
New patch, with coding style fixes recommended above.
Comment #18
brianV CreditAttribution: brianV commentedRe-upping patch with a new name to be retested. Patch applied cleanly against head here, so I have no idea why the testbot failed.
Comment #19
dmitrig01 CreditAttribution: dmitrig01 commentedHow about
$topic->first_new_topic
without the is_ just like sticky doesnt have is_ and similarly remove was_Comment #20
brianV CreditAttribution: brianV commenteddmitri,
it's a pretty common convention to prefix a boolean with is_ to hint at the type by the name.
If I had to judge by the name alone, I would assume 'first_new_topic' contained the nid of the first new topic, or something similar. 'is_first_new_topic' automatically implies that we are dealing with a boolean.
On the other hand, this convention isn't followed to strictly within Drupal core.
I agree 'was_first_new_found' is pretty nasty.
Comment #21
brianV CreditAttribution: brianV commentedNew revision.
I renamed $was_first_new_found to $first_new_found. However, I've left $is_first_new_topic alone for the reasons stated above.
Comment #23
brianV CreditAttribution: brianV commentedI accidentally removed a line I didn't intend to in the last patch, causing it to fail some tests.
New patch attached, hopefully the final one for this issue.
Comment #24
catch$is_first_new_topic should probably just be $first_new_topic or $first_new
This bit reads a bit awkwardly to me:
Could we do something like
(not tested)
Comment #25
brianV CreditAttribution: brianV commentedNew version posted.
I renamed $is_first_new_topic to $new_topic.
I've changed the one hunk to closer match what is posted in #6:
Please note that the code above is only executed once, due to checking $first_new_found. If that is omitted (as in #6), the loop is executed for every 'new' comment in the listing, which could be as many as 50 times.
Hopefully, this is the last patch for this issue.
Comment #26
brianV CreditAttribution: brianV commentedAfter chatting with catch in IRC, I present....
!!!!!REVISION 8!!!!!
Certified 100% bug, BPA and MSG free. This product was not tested on animals.
Comment #27
catchLooks good. I was going to suggest we write a test for this, but really that should be done when #355185: Add HTML validation to functional tests gets in. Waiting on the test bot.
Comment #28
catchSpotted one more thing - we use if / endif in template files rather than braces, sorry all these came one by one. Re-rolled with just that one change, this should be ready to go.
Comment #29
Damien Tournoud CreditAttribution: Damien Tournoud commentedNice, more step on the road to generating valid XHTML ;)
Let's get this in.
Comment #30
brianV CreditAttribution: brianV commentedRe: if / endif in template files..
I wasn't aware of that. Marking down in my book of 'odd little things about Drupal module coding'
Comment #33
brianV CreditAttribution: brianV commentedJust bumping this issue - needs to be rerolled. If someone gets to it before I do, good. Otherwise, I will get to it sooner or later.
Comment #34
tylor CreditAttribution: tylor commentedRe-roll of patch from #28.
Comment #35
brianV CreditAttribution: brianV commentedTests pass, looks good
Comment #37
brianV CreditAttribution: brianV commentedJust bumping again. Needs a reroll, but I don't have time to tacke it.
Comment #38
swentel CreditAttribution: swentel commentedReroll
Comment #39
alexanderpas CreditAttribution: alexanderpas commentednot that happy about this, shoudn't it be
<a id="new" />
This review is powered by Dreditor.
Comment #40
brianV CreditAttribution: brianV commentedLooks good to me. Personally, I don't think it's worth a reroll to compress it down to
<a id="new" />
Comment #41
alexanderpas CreditAttribution: alexanderpas commentedadded my own suggestion from #39
Comment #42
brianV CreditAttribution: brianV commentedComment #44
brianV CreditAttribution: brianV commentedRerolled once again. Setting to CNR so the testbot will look at it, but this has really been RTBC since early June.
Comment #46
brianV CreditAttribution: brianV commentedoops.
Comment #47
brianV CreditAttribution: brianV commentedSince this is just a reroll of a patch that has been RTBC since June, I am putting back to RTBC.
Comment #48
Dries CreditAttribution: Dries commentedIt would be great to see a screenshot of how this changes the behavior. I'm trying to understand how important this feature is (vs removing it).
Comment #49
sunThis is absolutely required for #653940: Clean-up: Tests do not report all errors.
Wraps too early.
Trailing white-space here.
Plenty of unnecessary parenthesis.
This is either not required or it is missing an array key.
I'm on crack. Are you, too?
Comment #50
brianV CreditAttribution: brianV commented@sun
Turns out I rerolled that badly. Re-rolled with your suggestions changed, the theme() call fixed, and tested thoroughly this time.
@Dries
As requested, I have also attached a screenshot which illustrates the change. Basically, there is no graphical change. The only change is that the first new icon (green) gets the
<a id="new" />
(green codeblock) while the remaining icons (red) don't get it. (red codeblock).This is, of course, used in links to the first new topic in the forum (eg., http://example.com/forum/1#new).
Previous behaviour was that each new forum icon would receive the
<a id="new" />
. This breaks XHTML validation, as each id element is required to have a unique name.Comment #51
sunThank you, well done!
Comment #52
cburschkaThis is technically valid XHTML, but not supported by even good browsers (including Firefox 3.5, Opera 10 and Google Chrome.)
Specifically, to get perfect support for this we would probably need to serve pages as
application/xhtml+xml
, creating a host of other problems.From http://dusan.fora.si/blog/self-closing-tags
See also this test: http://dusan.fora.si/blog/wp-content/uploads/2007/07/tags.html
To ensure cross-browser support, please make the above a
<a id="new"></a>
instead.This review is powered by Dreditor.
Comment #53
amateescu CreditAttribution: amateescu commentedIf this is still considered for D7, here's a reroll for current HEAD containg the fix suggested by @Arancaytar.
Comment #54
brianV CreditAttribution: brianV commentedGlad to see the reroll. I kind of ran out of steam rolling and re-rolling this patch (12 times!).
Looks good, was RTBC for a very long time, back to RTBC.
Comment #55
amateescu CreditAttribution: amateescu commented#53: 405238-53.patch queued for re-testing.
Comment #56
amateescu CreditAttribution: amateescu commented#53: 405238-53.patch queued for re-testing.
Comment #57
webchickWhile I am incredibly loathe to change anything to do with template files at this point, this does fix a legitimate bug, and I can't envision another way to do it. The good news is it seems to do so in a way that will not break BC in a theme that's already overridden this (they'll get the same XHTML validation errors as ever), and far better to get this fix in now than after RC.
Committed to HEAD. Thanks!