0

ok, this is what I have done so far but it is still not working.

First I wanted to add senders profile picture to the private message list on each user profile page. To accomplish that, I used the following code from drupal.org forum:

https://drupal.org/node/1549540#comment-5956560

It does work on my site, but it is using the default user picture. I would like to use a different image for users profile page. So I created an image field named profile_image. I am not pretty sure what is the best approach. On this page, they are trying to change the default user profile picture by the image field but for some reason it is not working for me:

How can I display a picture from a field as the user picture rather than the drupal default with user-picture.tpl.php?

I took the user-picture-tpl.php which had the following code:

<?php if ($user_picture): ?>
  <div class="user-picture">
    <?php print $user_picture; ?>
  </div>
<?php endif; ?>

I removed it and add this code:

<?php if (!empty($user->profile_image[LANGUAGE_NONE][0]['fid'])) {
  // Load the file
  $file = file_load($user->profile_image[LANGUAGE_NONE][0]['fid']);

  $account = user_load($account->uid);

  // Note the style name is "profile_picture" as explained in your question,
  // not "profile_pic" which was in your original code
  echo theme('image_style', array('style_name' => 'people_profile_image', 'path' => $file->uri));
}

Nothing is working yet. what I am doing wrong? could you please help me?

Thanks

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • Just to close this question, I ended up using the default user picture instead of the custom profile image. thanks – gjanet83 Jun 5 '14 at 17:19
0

You have made mistake in your field name, Drupal creates an machine name of any field prefixed as "field_" if you create it using Field UI. Using thumbnail as the style and also ensure that the style you have added -- people_profile_image is created in the Image Styles

so your code should be

if (!empty($user->field_profile_image[LANGUAGE_NONE][0]['fid'])) {
  // Load the file
  $file = file_load($user->field_profile_image[LANGUAGE_NONE][0]['fid']);
  $account = user_load($user->uid);

  // Note the style name is "thumbnail" and that your field name is
  // field_profile_image not profile_image which you have put in second line
  // which loads the file
  echo theme('image_style', array('style_name' => 'thumbnail', 'path' => $file->uri));
}
  • Thank you very much for your comment. I added your correction to user-picture.tpl.php but nothing is showing. hmm. Do you think it is because the way user picture are being called from the database like this code: drupal.org/node/1549540#comment-5956560 . I am using that exact code. It works, but not with my field_profile_image.. Thanks in advance – gjanet83 Apr 28 '14 at 17:03
  • Well it seems the template files gets data from template_preprocess_user_picture, which means this function needs to be overriden in theme template.php file or in a custom module to change the User Profile Picture. Please go through the api to find out how it can be done, and also use Devel module to get the variables. – pritywiz Apr 28 '14 at 19:44
  • Hi, Well, I´ve been giving it a try with no avail. And honestly, now I am not pretty sure what I am doing by now. I have Devel installed but not sure how to use it on this case. Could you please guide me? Thank you very much – gjanet83 Apr 30 '14 at 14:18
  • I would suggest you try it on your own, the function has to be written in your template.php file so that the user_picture variable is updated with the image of the field you have created. go through the api I have provided the linked to earlier. – pritywiz May 2 '14 at 6:07
  • Well, after spending long time looking for a fix, I decided to use the default user picture instead of a custom profile image. I don´t have much experience with php, so looking at the API was not that easy for me to figure how to add the image profile picture. Thanks – gjanet83 May 15 '14 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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