4

I would like to use the rules module's Set a data value action to set a user's profile picture whenever that user uploads an image of an "image" content type that I have created.

However, the user profile picture does not appear as an option in the data selector for site:current user. Is there another way to set the user profile picture using rules or am I out of luck?

3

Create a componnent in rule with this ! On the componnent you have 2 parameters. One for the user and another one for the file you want to use ! I use Drupal 7.

$uid = $user->uid;
$account = user_load($uid);
$thefile = file_load($file->fid);

$edit['picture'] = $thefile;
user_save($account, $edit);

Call the componnent from the rules you want. On my side i'm using a flag to trig the rules. The user mark an image to use it has a profile picture and it work.

I use this link has a starter to create the rule. http://taggartjensen.com/code-snip/drupal-7-set-user-picture-programmatically

Good luck !

1
  • The link is rotten. May you update it?
    – apaderno
    Jul 4 '14 at 12:20
2

Another solution is to use the User Picture Field module. This module allows you add an image field to user, and show it on user register form, after user register an account, this module will use the fid that upload by image field as user picture's fid.

The benefit of this approach is that you can manipulate the new field like other fields (you can't do that with the default "picture" field.)

This new field, which replaces the default field, then appears in most data selector lists that involve nodes.

Easy to use, requires no programming.

0
1

You will need to do some programming, enabling the php filter for a php action, get the uploaded file path, load the user, then create a new file, update the user picture file column , assign the picture on file_usage to the user

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.