Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
comment.module
Priority:
Major
Category:
Bug report
Assigned:
Reporter:
Created:
27 Mar 2010 at 13:43 UTC
Updated:
6 Jan 2025 at 06:38 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
derjochenmeyer commentedThis is true for all themes. It is confusing because the "Add new comment" link / anchor is pointing to the comment form which is the very next element on the page. I think this can be considered as a bug.
This patch removes the "Add new comment" link from the full node view if the comment form is displayed below the node.
I dont know if this breakes other use cases.
Comment #2
derjochenmeyer commentedAnd if it is a bug, it should be fixed for D7.
Comment #3
derjochenmeyer commentedComment #11
sunI don't see how this change could be remotely able to fix the described bug.
Comment #12
sunBetter title.
Patches should re-start from scratch and start with tests. We need to test the 2-3 different possible configurations and precisely verify our expectations.... if I'm not mistaken, then we already have a CommentTestHelper::postComment() method that asserts various comment settings; perhaps we can even squeeze those additional assertions into that.
Effectively, I think that the resulting logic that's required here is negated to the logic of the patch in #3. But yeah, let's start with tests first, ensure that tests are actually failing in HEAD, and afterwards, complete the patch to fix 'em.
Comment #13
sunCross-linking #583576: HTML link 'Add new comment' should not be display on book printer-friendly page
Comment #14
sunI can't help, but this entire function is totally b0rked. Attached patch should also fix the "@count NEW comments" string never appearing... (?)
Also, next to writing tests, someone needs to describe, explain, and reason the expected behavior. Currently, I guess the link is output under the assumption that there may be 100ths of comments, and if the comment form is output "below" on the same page, then you may find that link helpful to skip scrolling.
Comment #17
manarth commentedBartik hides the 'comment-add' link if the comment form is displayed (and also hides the link on teasers).
For Garland, ideally I'd like to see the comment-add link hidden only when there are no comments. If there are comments, if works well as a skip-link to go straight to the form.
Patch attached shows this (NB: this only affects the Garland theme, and should be viewed as an addition to the other patches mentioned in this thread - not a replacement).
Comment #19
Jeff Burnz commented#14: drupal.comment-add-link.14.patch queued for re-testing.
Comment #20
Jeff Burnz commentedSince #850740: unset Add New Comment link is not unset has been marked as a dup, please remove the cruft from Bartik's node tpl as part of this patch, else we can mark #850740 as postponed until this gets in and then fix Bartik later.
Comment #21
sunRight now, I'm considering any custom code in core themes for this link as bogus, and it likely needs to be removed. Instead, we want to fix the default behavior of Comment module.
However, as mentioned above, we need clear expectations in a test, so as to be able to fix Comment module's behavior accordingly.
Following patches should only add tests, so we see what actually fails. Afterwards, we merge back in the patch from #14.
Comment #25
EvanDonovan commentedOh, I had forgotten about this issue. I guess this is probably not going to get fixed in D7, but it is clearly not obvious what the correct fix is, so I am OK with that.
Comment #26
joachim commentedI agree with Sun. This sort of logic belongs in the module itself, not the themes.
> For Garland, ideally I'd like to see the comment-add link hidden only when there are no comments. If there are comments, if works well as a skip-link to go straight to the form.
This sounds like sensible behaviour to me.
Note that the comments I add call it the "post comment" form, which is wrong as it does not match the UI, but is consistent with the old comment a few lines up. I think it's best to keep consistent now and fix both of those in a later issue.
Comment #28
EvanDonovan commented@joachim: Looked at the code of the patch - the conditional seems to make sense. Not sure why there are exceptions...
Would there still need to be tests for this, since we are just modifying the internal logic of the function that outputs the "Add new comment" link?
Comment #29
joachim commentedThe property needed checking with empty().
New patch; ran the failing tests locally and they pass now.
Comment #30
sunThanks - merged earlier clean-ups and fixes into most recent patch.
Comment #31
EvanDonovan commentedI'll try to make the time to test this tomorrow.
Comment #32
EvanDonovan commentedHere is Garland with no comments before the patch: https://skitch.com/evandonovan/rbw8b/comment-pre-fix (buggy)
And it is with one comment, pre-patch: https://skitch.com/evandonovan/rbw8k/one-comment-pre-fix (OK)
And here is Bartik with one comment, pre-patch. The skip link is not showing up, just as it doesn't when there are no comments: https://skitch.com/evandonovan/rbw8w/bartik-one-comment-pre-fix (buggy)
Finally, here is Garland with no comments after the fix: https://skitch.com/evandonovan/rbwef/garland-no-comment-fix
The other two screenshots would be the same.
Reading up further in the thread, it looks like Bartik is deliberately hiding the add-comment link all the time. Since that's logic within Bartik, that can probably be handled in a followup. I think this is good to go. Stark has the same behavior as Garland now does, so I think the core logic is sane.
Comment #34
sunComment #35
webchickLet's get some tests in here that assure we're getting the behaviour we want. I was not able to easily parse this out of the issue, nor the patch.
Comment #36
joachim commented@#34 -- yes, it's meant to. Where's the comment form set to appear?
Comment #37
joachim commented> I was not able to easily parse this out of the issue, nor the patch.
As I understand it (and there are many cases, so everyone else please chime in)
- comment form on separate page:
-> link is to separate page at comment/reply/NID
- comment form on same page as node:
- node has comments
-> link is to the anchor on the form below the existing comments
- node has no comments
-> no link; the form is right there with the 'Add a comment' heading
I'm not really happy with the patch in #30 -- it makes the logic with the href for the link harder to follow, and these cleanups don't seem entirely related to this issue. But by all means let's file another issue to clean up the code first and then come back here :)
Comment #38
sunDetails on #34: Comment form on same page. 0 comments exist. View of an anonymous user, having "post comments" but not "view comments" permission.
UGH! That reminds me... #34 is off-topic for this issue: #799998: "post comments" permission does not work without "access comments"
There's no need to split those additional clean-ups into a separate issue.
Comment #39
joachim commented> View of an anonymous user, having "post comments" but not "view comments" permission.
Ah. That'll be the thing then! The logic counts the actual comments on the node, not the ones visible to the current user.
> There's no need to split those additional clean-ups into a separate issue.
I find they make the patch quite a bit harder to take in :/
Comment #40
manarth commentedIn principal, I think each (node) page should provide links/info for:
- Add comment
- View comments (including comment-count)
- View new comments
The layout of some themes may make some of these links redundant, in which case they can (and should) be safely removed by the theme. For example, a skip-link to the "Add comment" form would be redundant if the add-comment form was directly after the position of the skip-link.
The links should be made available for every theme by the core comment module, leaving it up to the theme to choose how to handle the links.
The attached patch adds tests for these (using Stark as the theme, because Bartik has - probably intentional - behaviour which deviates from the norm).
Four of these tests fail, because the comment module does not add all the links which I'd like to see added.
It'd also be good to see these tests extended to cover the other core themes too.
Comment #41
manarth commentedOK, I've changed my mind :-)
Links to new comments need not be shown, because the user is viewing the node page, so there are no new comments.
This means that the links should be:
- Comment count (with in-page link to the comment section).
- Add comment (with link to the comment form, whether there's in-page or a separate page).
This patch:
- Adds these links in the comment module.
- Adds tests for Stark and Bartik
- Patches Bartik so that the link to the add-comment form is only removed when there are no comments (because in this case, the comment form is displayed directly beneath the link).
There are dozens more tests which can be added to this patch, accommodating for different themes, permissions, comment settings (open/closed, in-page/separate-page), and number of comments, but here's a good start.
Comment #42
manarth commentedOh, lets kick the testbot off.
Comment #44
manarth commentedHmm.
In node.tpl:
It doesn't point out that this variable may not be set all the time (and therefore you should check isset($comment_count) before using it). Probably one for a separate issue.
I've updated the patch from #41 to check that $comment_count is set before using it (in the Bartik node template).
Comment #46
sunIn an attempt to fix this once for really ultimately all...
Comment #48
sunThat's what I'd call a test. mwuahahahahah
Note: Contains tests only. Expected to fail.
Comment #50
sunAlright - here we go! Based on these tests, it doesn't make sense to tackle #799998: "post comments" permission does not work without "access comments" in a separate issue anymore.
Comment #51
sunForgot to remove commented out tests.
Comment #52
sunLuckily, it seems we're going to revise that iteration over multi-dimensional conditions. Thus, just for later reference, the current and known to be working test results of this patch:
321 passes, 0 fails, 0 exceptions, and 92 debug messages
(Those shouldn't change)
Comment #53
joachim commented> * - Internal conditions: Various Comment module configuration settings and
* user access permissions.
* - External conditions: Whether the user is authenticated or not, and
* whether any comments exist.
I'd think of those more as configuration and, erm, another word I can't think of. But never mind about that.
* To account for all possible cases, this test implements two matrixes, one
The plural of matrix is matrices :)
Comment #54
sunLots of credits for this revised implementation go to dmitrig01 and chx.
What. A. Night. -- Awesomeness!
Comment #55
joachim commentedThis will still fail if there are comments but the user can't see them, no?
Can we put the two different hrefs in an if/else pattern so it's clear these are two alternatives, rather than the current overwriting pattern? The 'fragment' key belongs in that too.
... a different theme.
Not all of these are immediately obvious -- 'form', for instance. Could we maybe have a brief comment trailing each line, eg
'form' => blah, // Setting to the comment form location. Or will that just make it noisy?
Powered by Dreditor.
Comment #56
sunIncorporated #55 and accounted for already existing logic in theme_comment_post_forbidden(), which takes user registration settings into account.
Comment #57
sunForgot to remove commented out tests again.
Comment #58
sunUpdated the test code comments. Looks RTBC to me.
Comment #59
manarth commentedI'm not sure about this: the module is making assumptions about the theme's presentation.
This is assuming that the theme will render (in this order):
- node
- links
- comments
- comment form
and therefore, a link to the comment-form is redundant if there are no comments.
However, a theme might render in a different order, or put the comment-form in a sidebar. It's better for the module to provide the link even if there are no comments, and leave it up to the theme to choose whether that link should be rendered.
Comment #60
sun@manarth: The order in which links and page contents are rendered has no impact on the code that generates the links. This patch does not change how links can be rendered in a theme, or, what a theme can or cannot do with regard to comments and comment links.
Comment #61
manarth commentedThe problem is this: when the comment-count is 0, the module does not provide a link to the add-comment form.
This is based on an assumption that a link to the add-comment form would be unnecessary, because the add-comment form would be rendered directly following the link. I.e. the module is assuming that a theme will display the data in a particular way. If a theme then uses a different layout where a link would be useful, it has to duplicate the module's functionality in order to build the link to the add-comment form.
It would be better for the module to generate the link to the add-comment form (for all cases where the user has permission to add comments), and the theme can choose not to render the link, if that's appropriate for the way the theme lays out the content.
Comment #62
sunIn that case, the theme can still output a custom generated link manually. Modules and themes can change and alter lots of things, but if they do want to do things differently, then of course they may also need to care for possible further tweaks.
This patch is about Drupal core's defaults, which - in terms of the sub-issue you are raising - make sense for every theme I've ever built so far. Note that the raised edge-case scenario also contradicts the original purpose of this issue.
Lastly, the scenario you're describing actually rather maps to the "comment form on separate page" comment setting...
--
FWIW, also updating issue title, since #799998: "post comments" permission does not work without "access comments" has been merged into this patch and marked as duplicate.
Comment #63
sunGiven how many bugs + regressions this patch fixes, bumping to major.
Comment #64
EvanDonovan commented@sun: You've combined several issues into this patch, so I don't feel confident reviewing it anymore, since I would probably miss reviewing some of the behaviors that this fixes.
Does this count as an API change, or since this is the internal logic of the comment display functions, could this go in after RC?
Comment #65
EvanDonovan commented@manarth: I think the sane default, as I had said originally, is to not render the link when the comment form shows under the node and there are no comments yet. That was my initial issue, raised with Garland, but it applies to Stark as well. We should make the core behavior of Drupal's modules work with Stark in terms of the markup that is generated, and then if a theme is doing something unusual, it will use a preprocess/theme override.
Comment #66
sunFixed the example snippet in the phpDoc of generatePermutations().
Only #799998: "post comments" permission does not work without "access comments" has been merged into this patch. Thus, comment links as well as the comment form should properly appear according to comment settings and user permissions.
The code has been reviewed multiple times by joachim and manarth already. As the permutations test code reveals, it's close to impossible to test all possible configurations manually. Thus, manual testing could only be done for a few random samples. Aside from that, the code looks bullet-proof to me.
Comment #68
sun#66: drupal.comment-links.66.patch queued for re-testing.
Comment #69
sunThis patch performs extensive testing of almost all possible scenarios in which comment links may appear.
It should get in before D7 is released, as it fixes quite a couple of bugs exposed under certain conditions, from which most are even regressions to D6. I'm not sure what I can do to speed up the process.
Comment #70
EvanDonovan commented@sun: I will try to test a few use cases either tomorrow or on Saturday, although obviously I can't test everything. I won't have time until then. I will consider marking it RTBC after the testing, although I don't understand all the code.
Comment #71
sun#66: drupal.comment-links.66.patch queued for re-testing.
Comment #72
geerlingguy commentedSubscribe. I'd like this to get in before D7 release, and I'm going to do some testing later today.
Comment #73
sun#66: drupal.comment-links.66.patch queued for re-testing.
Comment #74
EvanDonovan commentedSorry for breaking my promise to test this. Client demands took precedence, sadly. I will test a few cases on Friday.
Comment #75
EvanDonovan commentedMerry Christmas, sun - I tested your patch :) It still applied to HEAD, though with some fuzz.
I tried the same test cases as in #32, with the same results. I am satisfied that this is fixing the original issue.
I also tested the case from #799998: "post comments" permission does not work without "access comments", both observing the initial broken behavior, and the new behavior. Now if a user can post comments but not view comments, they will see the "add new comment" link and it will work. However, their comments will not show up. I think that this could confuse people, but the earlier situation (hidden dependency of post comments on view comments, with a non-working link) was much worse.
I also reviewed the code and it looks sensible to me, though I am not expert in that. I think we definitely need to get this in before release.
Comment #76
EvanDonovan commented@geerlingguy: Care to second my review?
Comment #77
geerlingguy commentedI can try if I have a few minutes tomorrow. My desktop was borked last night, so I need to re-set up MAMP / my D7 testbed.
Comment #78
geerlingguy commentedComment links seem to function correctly in all situations - testing in Garland, of course. Bartik hides the Add new comment link on teasers by default, so no problems there, and this patch fixes the odd behavior of the link in Garland.
The 'Add new comment' link shows up again after a comment has been left, and simply links down to the comment form (also a desired behavior). I second EvanDonovan's RTBC. Commit, please!
Comment #79
EvanDonovan commented#66: drupal.comment-links.66.patch queued for re-testing.
Comment #81
sun#66: drupal.comment-links.66.patch queued for re-testing.
Comment #82
sunTestbot hiccup.
Comment #83
webchickI asked sun for an issue summary, since I can't figure out how this could possibly have been manually tested properly without one, and got something in reply basically like "It tests all permutations of comment link settings + permissions + something else," but my IRC client crashed and I lost what the exact wording was.
Reading the patch, this appears to be true. The new generatePermutations() function added by this patch and called by testCommentLinks() definitely provides much more robust testing than we currently have. And reading through assertCommentLinks() does a fairly decent job of explaining how the code is supposed to work.
I'm not a huge fan of all this abstraction... testCommentLinks(), setEnvironment(), assertCommentLinks(). It makes the test more difficult to follow than it needs to be. However, I can see that if you were to combine all of these down into one big-ass testX function, you'd end up with a pretty huge mess on your hands (ala comment_node_view(), oh snap ;)).
I asked sun if setEnvironment() ought to be moved into DrupalWebTestCase as a more general function and he said no, that it was just one of many possible ways to use the output of generatePermutations(), which is fair enough. I'm also not sure how I feel about it in general, so keeping it limited only to Comment module for now seems safer.
I'm very nervous to commit something so far-reaching this close to Drupal 7.0's release, now < 60 hours away. However, it does appear that due diligence was done to ensure that every possible combination of this stuff is tested properly, and it clearly fixes some long-outstanding bugs. Additionally, the manual testing that Evan and Jeff did, while not covering every single combination this patch touches, at least didn't run across anything too out of the ordinary in manual testing, which bodes well. That generatePermutations() function also looks like a really useful thing to provide to contrib modules for testing, as well, so it'd be nice to get it in for 7.0.
Therefore, committed to HEAD. Thanks a lot for all the hard work on this, folks!
Comment #84
EvanDonovan commentedThanks, webchick :)
Comment #85
sunRe-opened #850740: unset Add New Comment link is not unset for the remaining Bartik comment links fix.
Comment #86.1
mr.baileysCopy of the revision from October 6, 2011 - 01:38.