[user] is replaced with $account->name. This makes it difficult when trying to output all user names the same way by overriding theme_username().

Is there a reason that this line:

$values['user'] = $account->uid ? check_plain($account->name) : variable_get('anonymous', 'Anonymous');

Cannot be replaced with this line?

$values['user'] = theme('username', $account);

This would be a lot more consistent with how user names are output. If this change is not acceptable, then perhaps we could introduce a new token that does call the proper theme function.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robby.smith’s picture

+1 subscribing

Dave Reid’s picture

Title: [user] and theme('username') » User name tokens should use theme('username')
Version: 6.x-1.12 » 6.x-1.x-dev

Hmm...not even the core D7 tokens are using format_username. :/

Dave Reid’s picture

robby.smith’s picture

I was wondering if the patch will be available for Drupal 6 as well?
Thank you

Dave Reid’s picture

Well how is this supposed to handle theme_username when it returns HTML?

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

#5 still needs an answer

robby.smith’s picture

I looked around and the below is how it was done in the Mail Editor module.
http://drupal.org/node/792244#comment-2973904

--- mail_edit_user.inc	14 Sep 2009 00:29:43 -0000	1.1.2.2
+++ mail_edit_user.inc	16 May 2010 19:24:39 -0000
@@ -29,6 +29,7 @@
     case 'status_blocked':
     case 'status_deleted':
       $tokens['!username']= "User's username";
+      $tokens['!username_themed']= "User's username (themed)";
       $tokens['!site']= 'Site name';
       $tokens['!login_url']= 'One time login URL for password reset';
       $tokens['!uri_brief']= "Website's URL without the leading http://";
@@ -48,6 +49,7 @@
   $account = $mail['params']['account'];
   $language = $mail['language'];
   $tokens = array(
+    '!username_themed' => strip_tags(theme('username', $account, array('plain' => TRUE))),
     '!username' => $account->name,
     '!site' => variable_get('site_name', 'Drupal'),
     '!login_url' => user_pass_reset_url($account),
robby.smith’s picture

Status: Postponed (maintainer needs more info) » Active
ckng’s picture

I'm working on D7 Submitted By module and found that there is no way to have a $submitted with a linked user name, like we normally have for content and comment.

There should be 2 additional tokens through theme('username'), IMO:
- plain strip tags, [node:author:name_themed_plain]
- fully themed (with link, etc), [node:author:name_themed]

Dave Reid’s picture

@ckng: That's a much different issue. Please file a new issue.

ckng’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review
FileSize
1.22 KB

@Dave: I think it end up as the same issue, just that I've put it to my use case.

I would suggest [user:name] to remain as output from format_username().

It is essentially adding [user:name_themed] and [user:name_themed_plain] through theme('username'), that get propagated as [node:author:name_themed] & [node:author:name_themed_plain], respectively.

The name is a bit long though, any suggestion?

I've put together a quick patch, see attached.

Dave Reid’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Active

So in other words, it's a new token from what is being discussed here, and hence a feature request. Using theme_username() in the D6 token would still try to output as plain text. Please file a new issue.

Dave Reid’s picture

There is also no need for a user:name_themed_plain ... that's what user:name is for.

mstef’s picture

#11 shows the new tokens available but they're not getting populated for me.

mstef’s picture

There is also no need for a user:name_themed_plain ... that's what user:name is for.

I can still see a need for this. It will run theme_username() and strip the tags. Could easily be different than $user->name.

mstef’s picture

Looks like the patch is adding to the switch for taxonomy tokens.

mstef’s picture

Updated patch:

mstef’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review

Sorry for so many comments..

Chris Matthews’s picture

Issue summary: View changes

The 6 year old patch in #17 to token.tokens.inc applied cleanly to the latest token 7.x-1.x-dev and if applicable still needs review.