I am creating a view of users that displays a list of Users with Picture and Name. This drupal install allows facebook users to sign in and automatically have an account created. Their account is also added to this jCarousel view.

The problem I am facing is that when a user signs up from Facebook, but does not upload an image directly to drupal, their facebook picture does not show on the list. Anywhere else on the site, however, their facebook pictures shows with the profile.

On the views field, I have:

  • User:Picture
  • User:Name

Is there anyway to have a logic in the view where I can request the Facebook Picture if User:Picture is not available?

Thank you in advance,

1 Answer 1


You can use the Views PHP module and use PHP to create whatever logic you want for this image output.

This module allows the admin account (user 1) to add fields, filters and sorts to views which use PHP code. It also supports additional accounts when the core PHP Filter module is enabled.

This is the successor of Views Custom Field for both D6 and D7. The D6 version supports both Views 2 and Views 3.


While this module allows you to directly use PHP inside views which may be useful for quick and easy solutions, it is highly advisable to use regular handlers and plugins when available (or even to create one yourself). Take note that filtering and sorting a view using PHP always has a considerable perfomance impact.

So in your view you can have:

  • 3 fields, user profile picture, facebook picture and the php field used to display a picture.
  • for the user profile picture, make it a default image display and exclude it from the output.
  • for the facebook picture make it a default image display and exclude it from render output.
  • in the php field you simply want to check if a file exists for user profile picture and then drupal_render() or return the profile or facebook picture Views will have already formatted for you using the other 2 fields.
  • be sure the 2 image fields are higher up in the field list of the View than the PHP field, so the PHP field can make use of those values in code.


An alternative that is slightly less magical and tied to Views is to use Display Suite and add a Custom Field in display suite for a User. This custom field does basically all the logic between the 2 fields and it's literally a pseudo-field for Users. Views can then use the view_mode for Users that you've provided by DS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.