Problem/Motivation

When a view is configured to display the user picture field without linking it to the user profile page and the anonymous user role does not have permission to use Gravatar, no picture is displayed.

  1. Views prevents Drupal from displaying the user picture as a link by unsetting the user ID.
  2. Gravatar loads an anonymous user, unsetting the user picture provided by Views.
  3. Gravatar checks the permissions for the anonymous user instead of the real user.

Proposed resolution

  1. If a picture exists, do not unset it.
  2. Load the user by mail to check permissions.

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions #19
Update the issue summary Instructions #19
Add automated tests Instructions
Update the patch to incorporate feedback from reviews (include an interdiff) Instructions #21
Manually test the patch Novice Instructions
Add steps to reproduce the issue Novice Instructions
Embed before and after screenshots in the issue summary Novice Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions

Original report by nothinghere

Hi,

On my dev site : Gravatar generate a default picture for users if they don't choose one by default.

I've created a view with "Views UI" :
* Field : User > Display picture
Here is the bug : No picture displaying.

I want to display Gravatar picture of my user when they don't choose one by default.

How can I do that?

Thank you.

Issue fork gravatar-1568162

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nothinghere’s picture

No one try to get Gravatar displayed with a view ?

joshintosh’s picture

Yep, doesn't seem to display Gravatar when you create a user View.

Morten Najbjerg’s picture

Is this feature on the roadmap for this module? Gravatar through views would be much appreciated.

mavimo’s picture

Component: Miscellaneous » Code
Assigned: Unassigned » mavimo
Category: support » feature
Status: Active » Reviewed & tested by the community
StatusFileSize
new3.04 KB

Patch attached

Status: Reviewed & tested by the community » Needs work
luksak’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.32 KB

This patch didn't apply. I applied it manually but no field was exposed to views.

I created a first working version of this. Please review my views code since this is my first views handler ever. It would be nice to get some feedback.

Status: Needs review » Needs work
smg23’s picture

would be very nice to have this fix working!

yuriy.sychenko’s picture

Gravatar added field in views, but does not show anything unfortunately :(

acouch’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB

I rerolled the above patch with the latest dev. I also added the option of being able to use the uploaded picture a user added instead of the Gravatar if the user has uploaded a picture to their profile. That option is off by default.

Status: Needs review » Needs work
acouch’s picture

Status: Needs work » Needs review

This test fails because there is no test. Maybe because of the stub functions here: http://drupalcode.org/project/gravatar.git/blob/refs/heads/7.x-1.x:/grav...

inky@inky3d.com’s picture

is there any hope for Gravatar images being able to be used in Views?

paulo_graca’s picture

I've had the same problem, and the way I've tried to fix it was through the views template and gravatar_get_gravatar function:

  $user_pict = array(
      '#type' => 'html_tag',
      '#tag' => 'img',
      '#attributes' => array(
          'src' => gravatar_get_gravatar($row->users_node_mail)
      ),
      '#prefix' => '<div class="user-image">',
      '#suffix' => '</div>'
  );  
  print render($user_pict);
adshill’s picture

#14 - Can you give more details to how you implemented this?

#12 - Patch applied but doesn't seem to work. I got: The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.

mglaman’s picture

Just applied patch from #10 against latest dev at it worked.

d.sibaud’s picture

Issue summary: View changes

the #10 patch it's ok for logged in users, but if I try to show comments (through a relation with Comment: Author and Comment: Content) made by anonymous users with a gravatar linked to the email inserted into the comment form: their gravatar wan't show. As opposite to the node comment thread visualization, where their gravatar are shown.

In some way it is possible to add also a check on the $values->users_comment_mail in the newly created views_handler_gravatar.inc, but the value is not retrieved by the views query. Sure it's more matter of views and comment modules than the gravatar one, but I share my experience here because my first need was born from the gravatar module.

darren oh’s picture

darren oh’s picture

Title: Views : display user picture doesn't display gravatar » Fix missing user picture in Views
Assigned: mavimo » Unassigned
Category: Feature request » Bug report
Priority: Normal » Major
Issue summary: View changes
StatusFileSize
new2.53 KB

I can reproduce this bug when I set the picture field to display without a link to the user’s profile page. Views unsets the user ID field in this case, preventing Gravatar from checking user permissions. A workaround is to give the anonymous role permission to use Gravatar. However, uploaded user pictures will always be replaced with the Gravatar.

Status: Needs review » Needs work

The last submitted patch, 19: gravatar-views-missing-picture-1568162-19.patch, failed testing.

darren oh’s picture

Issue summary: View changes
StatusFileSize
new292 bytes
new3.15 KB
darren oh’s picture

Status: Needs work » Needs review
darren oh’s picture

jacob.embree’s picture

Issue summary: View changes
Issue tags: -Needs manual testing

I can confirm that this patch fixes the issue, but I haven't written any automated tests.
The manual steps to reproduce are:

  1. Enable Views UI and Gravatar
  2. Enable user pictures on profiles
  3. Use a generated default image in the Gravatar settings
  4. Create a view of users that includes the profile picture without the checkbox to link to the user
  5. Observe that before the patch the default images are not displayed, and after the patch they are.

rukayya’s picture

Hi,

You can fix this using views template. Gravatar has it's own function gravatar_get_gravatar using which you can render it within your views template.

I have fixed this as below. I have added below code in my views-myviewname.tpl.php

 $profile = array(
      '#type' => 'html_tag',
      '#tag' => 'img',
      '#attributes' => array(
          'src' => gravatar_get_gravatar($row->users_node_mail)
      ),
      '#prefix' => '<div class="user-image">',
      '#suffix' => '</div>'
  );  
  print render($profile);

reenaraghavan made their first commit to this issue’s fork.