Fixed Can't set username for xf:avatar

Kirby

Well-known member
Affected version
2.2.13
Template tag xf:username accepts attribute username which allows to override the username but template tag xf:avatar does not process this attribute.

So if a username is override for the user link and a dynamic avatar is rendered, the latter is taken from the the username in user entity causing an inconsistent display (Overriden username in user link + letter from original username)
 
The avatar function call it gets compiled into supports a defaultname attribute, unless I'm misunderstanding:

HTML:
<xf:avatar user="{{ null }}" size="xxs" defaultname="John Smith" />
 
defaultname ist not the same as username, defaultname for xf:avatar is only used if user is not a User entity.

With xf:username it is possible to pass in a username that will always override the username from user

See PHP code:
PHP:
public function fnUsernameLink($templater, &$escape, $user, $rich = false, $attributes = [])
{
    $escape = false;
    if (isset($attributes['username']))
    {
        $username = $attributes['username'];
    }
    else

vs.

PHP:
public function fnAvatar($templater, &$escape, $user, $size, $canonical = false, $attributes = [])
{
    [...]
    if ($user instanceof \XF\Entity\User)
    {
        $username = $user->username;
        [...]
    }
    else
    {
        if (isset($attributes['defaultname']))
        {
            $username = $attributes['defaultname'];

So if user is a User entity it is not possible for the avatar to use a different username.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.7).

Change log:
Allow overriding avatar usernames when a user is specified
There may be a delay before changes are rolled out to the XenForo Community.
 

Similar threads

Back
Top Bottom