The views/modules/user/views_handler_field_user_picture.inc file, which handles the user picture field, does not include the users mail field in the query.

I agree that -without the Gravatar module - this is probably useless in most cases... but
1) It is a negligable hit to include mail
2) without the mail field, Gravatar cannot pick-up unique avatars per user (at least not without doing an extra hit per user).

The fix?

class views_handler_field_user_picture extends views_handler_field {
  function construct() {
    parent::construct();
    $this->additional_fields['uid'] = 'uid';
    $this->additional_fields['name'] = 'name';
    $this->additional_fields['mail'] = 'mail';
  }

  function element_type() {
    return 'div';
  }

  function render($values) {
    // Fake an account object.
    $account = new stdClass();
    $account->uid = $values->{$this->aliases['uid']};
    $account->name = $values->{$this->aliases['name']};
    $account->mail = $values->{$this->aliases['mail']};
    $account->picture = $values->{$this->field_alias};

    return theme('user_picture', $account);
  }
}

Basically, add the mail field to the class.

CommentFileSizeAuthor
#6 views_user_picture.patch500 bytesjcmarco
#1 views-657442.patch1.1 KBdagmar

Comments

dagmar’s picture

Version: 6.x-2.8 » 6.x-3.x-dev
StatusFileSize
new1.1 KB

Yes, make sense. However you should provide a patch to mark an issue as Needs Review.

Don't worry, here is it.

nicholasthompson’s picture

Thanks Dagmar - sorry I didn't provide a patch, but as you can see from the post time it was pretty much 17:30 which is more commonly known as Home Time where I work :-)

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to all branches.

Mark_Watson27’s picture

Status: Fixed » Needs work

Since I applied the latest DEV version of 6.x-2.x-dev I get
Fatal error: Cannot access empty property in /var/www/sites/all/modules/views/modules/user/views_handler_field_user_picture.inc on line 23

changing
$this->additional_fields['name'] = 'mail';
to
$this->additional_fields['mail'] = 'mail';
resolves it.

merlinofchaos’s picture

Status: Needs work » Active

'needs work' is a good way to make sure an issue never gets looked at.

jcmarco’s picture

Status: Active » Needs review
StatusFileSize
new500 bytes

Confirmed, the patch was buggy.
Mark_Watson27 was right.
New patch:

Mark_Watson27’s picture

Apologies for incorrect usage of 'needs work' will note for future reference.
Thanks
Mark

dagmar’s picture

Category: feature » bug
Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Yes, it was my mistake, sorry.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

Status: Fixed » Closed (fixed)

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