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]).

Comments

dave reid’s picture

Status: Active » Needs review
Issue tags: +token
StatusFileSize
new2.29 KB
dave reid’s picture

StatusFileSize
new1.62 KB

Revised for HEAD.

dave reid’s picture

Status: Needs review » Needs work

Needs 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.

dave reid’s picture

Title: The [comment:author] and [comment:name] should use format_username() and Anonymous user name. » [comment:name] duplicates [comment:author], and the latter should use format_username()
Status: Needs work » Needs review
Issue tags: +realname, +format_username
StatusFileSize
new5.01 KB

Needs 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

sun’s picture

Status: Needs review » Needs work
+++ modules/comment/comment.tokens.inc	21 Nov 2010 22:03:45 -0000
@@ -87,7 +83,7 @@ function comment_token_info() {
+    'description' => t("The author of the comment."),

Should use single quotes.

+++ modules/comment/comment.tokens.inc	21 Nov 2010 22:03:45 -0000
@@ -131,19 +127,21 @@ function comment_tokens($type, $tokens, 
+        case 'author':
+          $name = $comment->name;
+          if (!empty($comment->uid) || !drupal_strlen($comment->name)) {
+            $account = user_load($comment->uid);
+            $name = format_username($account);
+          }

The user_load() should only happen if uid > 0. For anonymous users, it's 100% overhead.

Powered by Dreditor.

dave reid’s picture

Status: Needs work » Needs review

Doesn'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.

dave reid’s picture

Version: 7.x-dev » 8.x-dev
holtzermann17’s picture

StatusFileSize
new310.54 KB

I 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:

(Content) Content: Title (§ )
Comment: Updated date
Comment: Title
Comment: Author (by )
Comment: Comment
Global: Custom text

And the result is that the Author fields are all shown as "Anonymous" even though the authors should be known.

holtzermann17’s picture

Probably the recent comments issue is a related problem in the views module, I made a separate bug report there: http://drupal.org/node/1210338

holtzermann17’s picture

Er... nevermind. I hadn't actually imported the 'name' fields. Sorry for the disruption.

rkjha’s picture

StatusFileSize
new4.95 KB

Rerolled for 8.x

rkjha’s picture

Issue tags: -token, -realname, -format_username

Status: Needs review » Needs work
Issue tags: +format_username

The last submitted patch, 920056-tokens-format-username-D7.patch, failed testing.

rkjha’s picture

Assigned: dave reid » rkjha
Status: Needs work » Needs review
StatusFileSize
new4.96 KB

format_username() renamed to user_format_name()

quietone’s picture

This 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?

quietone’s picture

Oops, 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.

quietone’s picture

StatusFileSize
new5.16 KB

Trying again

Status: Needs review » Needs work

The last submitted patch, 920056-tokens-user-format-name-D8.patch, failed testing.

andypost’s picture

Issue tags: +Needs reroll

code changed a lot. also related changes coming in #2028025: Expand CommentInterface to provide methods

quietone’s picture

Issue summary: View changes
StatusFileSize
new4.88 KB

Wow, that week became 4 months.

quietone’s picture

Status: Needs work » Needs review
Alumei’s picture

Issue tags: -Needs reroll
StatusFileSize
new2.69 KB

Re-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.

ianthomas_uk’s picture

This doesn't do what the issue summary says at all (presumably fixed elsewhere), instead it just fixes a problem mentioned in #4.

Status: Needs review » Needs work

The last submitted patch, 22: 920056-tokens-user-format-name-22.patch, failed testing.

andypost’s picture

Assigned: rkjha » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.12 KB

Re-roll, fix to use user name
Added test

Status: Needs review » Needs work

The last submitted patch, 26: 920056-comment-author-token-26.patch, failed testing.

andypost’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update +Needs change record
StatusFileSize
new3.6 KB

Green and needs review.
Updated summary

andypost’s picture

quietone’s picture

@andypost thanks for the clear issue summary.

Patch worked for me, passed all the comment tests.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

looks 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

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This 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!

  • alexpott committed a36ff84 on 8.0.x
    Issue #920056 by Dave Reid, andypost, quietone, rkjha, Alumei: Fixed [...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.