Problem/Motivation
CommentForm does a loadByProperties using the formatted username. This is nonsense. In fact much of the code involved with previewing comments and comment forms is based on extremely old code that is no longer need.
This patch will changes the way an admin can edit the name of the user who makes the comment. In HEAD we have a single field that is switched to do different things in different situations:
- Anonymous user on the comment add form or comment preview it is a free text field for the anon user to provide a name
- Logged in user on the comment add form or comment preview it is a item field that displays the name to the user (this is unnecessary the user knows their name and makes the form basically uncacheable)
- Comment admin whilst editing someone else's comment - it is an entity reference autocomplete field
Proposed resolution
Remove all the old unnecessary code... and bring some sanity to the form and make it cacheable:
- A free text field to allow anon's to add provide their name - this field is not displayed to logged in users and is displayed to comment admins when editing
- No username is displayed to logged in users in the comment add form or preview.
- Comments admins are displayed a new entity reference field so they can change the owner of a comment
Remaining tasks
Review
Commit
User interface changes
For a logged in user they no longer have their name displayed in the comment form.
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #91 | 2571909-2-90.patch | 17.34 KB | effulgentsia |
Comments
Comment #2
larowlanThis field can only be edited by admins, are you saying the default value is not username?
Comment #3
larowlanCan with on this tomorrow, unless someone beats me to it
Comment #4
mr.baileysComment #7
alexpottComment #10
andypostAny reason to make it translatable?
this string will appear in translations without need
Comment #11
mr.baileysComment #12
morenstratNot sure, but maybe #2566245: Comment author name overridden by hook_user_format_name_alter() is related?
Comment #13
larowlanComment #14
larowlanThis is blocked on #2112679: getUsername() should return the username getDisplayName() for the formatted user name
Comment #15
larowlanLooked at the patch, no its not
Comment #16
larowlanSigh #2227503: Apply formatters and widgets to Comment base fields would probably have resolved this. Wonder if its too late
Comment #17
larowlanworking on fails
Comment #18
larowlanComment #21
znerol commentedClosing #2566245: Comment author name overridden by hook_user_format_name_alter() as a duplicate of this issue, since the patch here is actually solving the problem in a more appropriate way. IMHO it would be appropriate to give @dunix credits here though.
Comment #22
andypoststill issue
Comment #23
your_inner_alexpott commented@andypost if l.d.o picks up translatable strings from test modules then that is the issue - no?
Comment #24
lauriiiTrying to proceed this since this would help #2559971: Make SafeMarkup::format() return a safe string object to remove reliance on a static, unpredictable safe list
I think we could create SafeString object there manually even though its internal because its only for a testing purpose. I added a @todo to point out that it could be changed to SafeMarkup::format() after it returns a SafeString object.
Comment #27
lauriiiComment #30
stefan.r commentedthis is blocking a critical
Comment #31
larowlanworking on the test fail, pinging laurii on irc for guidance
Comment #32
larowlanAs discussed on irc
Comment #33
larowlanAs per discussion on irc with @stefan_r
Comment #35
amateescu commentedShould we be worried that the patch from #32 failed on the old testbot but passed on DrupalCI, or is that just random failure?
Comment #36
stefan.r commented@amateescu I think that may have been a random failure indeed - thanks for spotting that.
We changed
<em class="placeholder">to<em>, so let's change the test just to be sure.Comment #37
stefan.r commentedI ran #32 lot's of times times locally. Could not reproduce this so I don't think the specific
<em>in #34 was the problem - let's ignore the failure?Comment #38
dawehnerWe wondered why this changed more than actually needed. Yes, using #access would be nice, but why is that in scope of this particular issue?
@stefan.r and @dawehner could not figure that out.
Comment #39
stefan.r commentedconsidering this has been bumped to critical maybe let's revert any out of scope changes?
Comment #40
nlisgo commentedcomma needed at end of line.
The message can be in single quotes now as it no longer has an apostrophe.
Found a couple of little niggles.
Comment #41
stefan.r commentedreroll - includes the nits from #40
Comment #42
stefan.r commentedminimal patch just to see what fails
Comment #46
stefan.r commentedthis seems like an unrelated fail? Value array ( ) is equal to value array ( 0 => array ( 'title' => 'example EN', 'sticky' => 'Off', ), 1 => array ( 'title' => 'example ES', 'sticky' => 'On', ), ).
Comment #48
alexpottThis is also extremely problematic - which is why I split up the name element into two elements. The latest patch does not address this loadByProperties().
Furthermore the solution has the added benefit of getting has quite a few steps closer to making the comment add form cacheable which is in everyone's interest. This is because there are way less conditionals when building the form. Also less conditionals make it more robust and easier to test.
Comment #49
larowlan+1 for going back to #33
Comment #50
alexpottThe patch in #32's failure on pifr (old testbot) is a known pifr issue that sometimes occurs and definitely is not caused by this patch.
GET http://ec2-52-11-109-200.us-west-2.compute.amazonaws.com/checkout/test_user_name?uid=ktp2q43a returned 0 (0 bytes).Comment #51
alexpottAnother reason to do #33 is that having the anonymous user entered name in a different field from the admin edited user entity reference is that they are completely different things. Trying to make them the same thing results in errors like this.
Comment #52
larowlanIt also brings us closer to #2227503: Apply formatters and widgets to Comment base fields which has separate widgets for each field (with access controlled by the existing field access)
Comment #54
stefan.r commentedyeah why not - reuploading #41
Comment #57
alexpottRemoving unrelated hunks from #54 and fixing tests.
Comment #58
upchuk commentedI think #2572553: Incomprehensible validation message when anonymous tries to submit comment with an existing username is related since we get some weird validation issues because of the Name field...
Comment #59
wim leersNit: we use the short array syntax elsewhere, so also should here.
Nit: s/author-ID/author ID/
#accesscan also be anAccessResultInterfaceobject.Nope, I was wrong, this code fully controls
#access, and therefore it can never be anAccessResultInterfaceobject, hence the code is correct.Nit: s/Web-user/Web user/ + s/comment-author/comment author/
Nit: s/Username's/Usernames/
I fixed all these nits.
Comment #60
wim leersWe no longer set this cache context, because it is no longer necessary.
\o/ \o/ \o/ \o/
This is what it now looks like, for all users, including an authenticated user:

Comment #61
wim leers#60 means we can now finally delete this piece of code, which TBH should've already been removed in #2543334: Auto-placeholdering for #lazy_builder with bubbling of contexts and tags, but now is also completely unnecessary, which is even better :)
Comment #62
wim leersThis part in particular of #61 is now wrong and must be updated here, in this issue, so it remains in sync with
CommentForm, i.e. with this particular part that is now gone:And if we remove that first quoted bit, we might as well remove the entire thing, which is exactly what the #61 interdiff does.
Comment #65
alexpottWorking on this
Comment #66
alexpottFixing tests and removing more dead code.
Comment #67
andypostOverall this great, just nits
looks a separate bug
looks new use is unused
Comment #68
upchuk commentedRemoving the unused 'use' statement.
Comment #69
jhedstromre: #67.1, not a bug really, since that permission is intentional, similar to not being able to see a node title if one cannot access the node.This isn't actually true :)
Comment #70
upchuk commentedDid some manual testing of the Comment preview and things seem to look ok, except for a couple of issues tackled elsewhere:
* #2574597: Comment body doesn't show up in preview for Anonymous users
* #2572553: Incomprehensible validation message when anonymous tries to submit comment with an existing username
Comment #71
upchuk commentedre: #67.1, it is a bug and there is an existing issue for it: #2471154: Anonymous user label can't be viewed and auth user labels are only accessible with 'access user profiles' permission
Comment #72
berdirOk, we had lots of reviews, manual testing, found various bugs but nothing caused by this. Code looks good to me as well, awesome cleanup and performance improvement.
Comment #73
wim leersComment #74
alexpottComment #75
effulgentsia commentedAdding credit to @dunix per #21.
Comment #76
effulgentsia commentedAdding issues from #70 and #71 as related issues. I haven't fully wrapped my head around what the nature of that relationship is though: i.e., whether they're completely independent issues or in some way affected by this.
Comment #77
berdir@effulgentsia: Both are existing bugs in HEAD. We just found them while testing this and are working on fixing them separately. They are otherwise not related to this issue.
Comment #78
effulgentsia commentedI haven't fully grokked all of the changes in this patch yet, and possibly I need to do some manual testing in order to, but this jumped out at me as potentially problematic:
If getDisplayName() returns a SafeString, then we'd be populating the author name with HTML, but AFAICT, the comment author name is always rendered elsewhere as plain-text. Should we change this to:
Kind of verbose, but given the explicit flexibility of AccountInterface::getDisplayName() returning either plain-text or SafeString, any other suggestions on how to do this?
Comment #79
effulgentsia commentedHm, maybe #78 isn't a problem, since Comment::getAuthorName() ignores what's in the 'name' field anyway for authenticated users. But that then raises the question of why set it?
Comment #80
alexpott@effulgentsia yep you are right - setting the name there makes no sense.
Comment #81
berdirMore code removed, tests are passing, looks good to me. Nice!
Comment #83
berdirI meant to do this.
Comment #84
effulgentsia commentedThanks! #80 definitely resolves that concern. I still want some more time with this patch before I can feel comfortable committing it, but I don't object to someone else committing it before me if they're comfortable with it. I'll try to get to this within the next 24 hours if no one beats me to it.
Comment #85
larowlanTaking for a manual spin
Comment #86
larowlanScreenshots - all looks good.
Confirmed the anonymous name isn't retained if the comment is switched to an authenticated user and then back to anonymous.
Looks good to me - one final question - should we name the field
uidinstead ofadmin_select- as that is the base-field we're editing - which would also align with #2227503: Apply formatters and widgets to Comment base fieldsComment #87
stefan.r commentedYay for extra manual testing!
Comment #88
alexpott@larowlan good idea - leaving it at rtbc.
Comment #89
alexpottDiscussed comment administration wrt comment editing with @effulgentsia. @effulgentsia noticed that in order to set the name when an admin converted a comment form a registered user you would have to edit a comment twice. The patch attached fixes this. It also ensures that the author name only has a default value when dealing with anonymous users.
Comment #90
alexpottAlso noticed whilst testing that "Edit own comments" is meaningless for anon users - which is a good thing - but potentially confusing.
Comment #91
effulgentsia commentedHere's a little cleanup of test code.
Comment #92
effulgentsia commentedI'm happy with #89, so as long as bot is happy with #91 and someone RTBC's that interdiff, I can commit.
Comment #93
alexpottI've tested the latest changes to comment administration and the #states implementation works nicely - see http://g.recordit.co/am1JyIVSL9.gif
Comment #94
alexpottThe interdiff in #91 looks great.
Comment #95
effulgentsia commentedPushed to 8.0.x!
Comment #97
wim leersSee #2552873-17: node/1 flamegraphs and #2552873-18: node/1 flamegraphs. This caused a big performance regression: the comment form still has a
max-age=0that is bubbled, therefore the entire node is no longer render cached…The combination of #2463567: Push CSRF tokens for forms to placeholders + #lazy_builder plus #2578855: Form tokens are now rendered lazily, allow forms to opt in to be cacheable would solve this regression.
Comment #99
andypostThis issue leads to data loss #2614504: Values of 'name' & 'email' fields should be NULL when comment has author (uid > 0)
Comment #100
quietone commented