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.
Comments
Comment #1
dagmarYes, make sense. However you should provide a patch to mark an issue as Needs Review.
Don't worry, here is it.
Comment #2
nicholasthompsonThanks 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 :-)
Comment #3
merlinofchaos commentedCommitted to all branches.
Comment #4
Mark_Watson27 commentedSince 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 23changing
$this->additional_fields['name'] = 'mail';to
$this->additional_fields['mail'] = 'mail';resolves it.
Comment #5
merlinofchaos commented'needs work' is a good way to make sure an issue never gets looked at.
Comment #6
jcmarco commentedConfirmed, the patch was buggy.
Mark_Watson27 was right.
New patch:
Comment #7
Mark_Watson27 commentedApologies for incorrect usage of 'needs work' will note for future reference.
Thanks
Mark
Comment #8
dagmarYes, it was my mistake, sorry.
Comment #9
merlinofchaos commentedCommitted!