Problem/Motivation
There's 2 tokens for comment author name:
[comment:name] & [comment:author] they returns the same data.
PS: historically it was a name provided in comment submit form.
Proposed resolution
Remove [comment:name] as dumplicate
Extend test for anonymous comment author token.
Remaining tasks
Commit
User interface changes
no
API changes
No more [comment-name] token
Original report by @Dave Reid
If you have a comment from a truly anonymous user (they didn't enter their name in the comment form), if you use [comment:name] you get an empty string, when you should get the result of variable_get('anonymous', t('Anonymous'));
Similarly, for registered users that have made comments, the [comment:author] and [comment:name] tokens should be using format_username() rather than the raw $comment->name.
Also for anonymous users, we should allow [comment:author] to work on a basic level (by re-using the logic in [comment:name]).
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 920056-comment-author-token-28.patch | 3.6 KB | andypost |
Comments
Comment #1
dave reidComment #2
dave reidRevised for HEAD.
Comment #3
dave reidNeeds to be re-rolled to use check_plain on the format_username() result, and the logic for anonymous is unnecessary as format_username() handles it for us.
Comment #4
dave reidNeeds to be re-rolled to use check_plain on the format_username() result, and the logic for anonymous is unnecessary as format_username() handles it for us. And we just need to get rid of [comment:name] because all it does is duplicate
Comment #5
sunShould use single quotes.
The user_load() should only happen if uid > 0. For anonymous users, it's 100% overhead.
Powered by Dreditor.
Comment #6
dave reidDoesn't have to use single quotes - not a reason to bump this to needs review.
If the comment name is empty, we need to give some kind of user object to format_username(). It should only happen for registered users, and comments where the name was empty (and the anonymous value is kept in the entity load cache), so it's only 100% overhead the first time. Also remember tokens are *dynamically* generated so this code does not execute if the [comment:author] token is not used.
Comment #7
dave reidComment #8
holtzermann17 commentedI tried applying the patch and it did not resolve an issue I'm experiencing with my view of Recent Comments. The view is set up like this:
And the result is that the Author fields are all shown as "Anonymous" even though the authors should be known.
Comment #9
holtzermann17 commentedProbably the recent comments issue is a related problem in the views module, I made a separate bug report there: http://drupal.org/node/1210338
Comment #10
holtzermann17 commentedEr... nevermind. I hadn't actually imported the 'name' fields. Sorry for the disruption.
Comment #11
rkjha commentedRerolled for 8.x
Comment #12
rkjha commented#4: 920056-tokens-format-username-D7.patch queued for re-testing.
Comment #14
rkjha commentedformat_username() renamed to user_format_name()
Comment #15
quietone commentedThis is my attempt at the reroll process.
The patch in #14 failed to apply and looking at the code it is still applicable. So, I made a new patch. But, I can't attach it because it exceeds the maximum upload size of 3MB. The new patch is 5MB like the others in this issue.
How do I attach it?
Comment #16
quietone commentedOops, sorry all. I wrote that just before going to bed and clearly wasn't paying attention to what I was reading or what file I uploaded.
I hope to sort that within the week.
Comment #17
quietone commentedTrying again
Comment #19
andypostcode changed a lot. also related changes coming in #2028025: Expand CommentInterface to provide methods
Comment #20
quietone commentedWow, that week became 4 months.
Comment #21
quietone commentedComment #22
Alumei commentedRe-roll for patch from #20.
Found no usecase for format_username as it is now only a wrapper around '$account->getUsername()' which seems to be used in the places where this patch used format_username.
Comment #23
ianthomas_ukThis doesn't do what the issue summary says at all (presumably fixed elsewhere), instead it just fixes a problem mentioned in #4.
Comment #26
andypostRe-roll, fix to use user name
Added test
Comment #28
andypostGreen and needs review.
Updated summary
Comment #29
andypostCR https://www.drupal.org/node/2371365
Comment #30
quietone commented@andypost thanks for the clear issue summary.
Patch worked for me, passed all the comment tests.
Comment #31
larowlanlooks rtbc to me
@catch noted in #2031901: Remove node tokens from comment.tokens.inc that he's happy for these cleanups to go in now
Comment #32
alexpottThis issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed a36ff84 and pushed to 8.0.x. Thanks!