0

Is it possible with custom module to detect occasion when user saves/updates his profile2 profile ? ( i know it is possible with rules but want to do it programatically in custom module).

And from that point, is it possible to load user data (the fields of profile2 profile) that just did the changes ?

Thanks for clues!

2

Yes it is possible, you can use the generic hook_entity_presave (or update/insert). There is also a specific hook for profile2 as well, hook_profile2_presave (or update/insert), but it requires the Rules module to be enabled.

  • Thanks! So, bare presence of hook_profile2_presave function in a module creates a "watchdog" for bare occasion of saving profile ? I tested it and it seems so.. One does not need to invoke that function, it seems it triggers when saving occure for any user... am i right ? – NenadP Oct 29 '12 at 23:05
1

I did this a couple weeks ago, with updating the users mailchimp info on saving the profile. Here is what I think you are trying to do.

YOURMODULE_profile2_update($profile) {
  // $profile contains the updated profile2 information so you can now
  // do whatever you would like to do with $profile info.
  // In my case I had to load the account again because I needed the 
  // user object so I used:

  $account = user_load($profile->uid, TRUE);

}

For more information check out hook_profile2_update

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.