Using Profile Fields in the 'new account' notification email

hubris - June 1, 2009 - 16:31
Project:Advanced User
Version:6.x-2.2
Component:Feature
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Drupal 6.12, Advanced User and Profile modules active.

I'm trying to get some of the Profile fields into the 'New User' notification email that gets sent by Advanced User when a new account is created. I've been messing with the following function in Advanced User:

function _advuser_get_variables($user) {
  return array(
    '%user_name' => $user->name,
    '%site' => variable_get("site_name", "drupal"),
    '%uri' => url('user/'. $user->uid, array('absolute' => TRUE)),
    '%user_email' => $user->mail,
    '%user_status' => t($user->status ? 'Active' : 'Blocked'),
    '%user_theme' => empty($user->theme) ? t('DEFAULT') : $user->theme,
    '%user_created' => strftime('%x %X', $user->created),
    '%user_language' => empty($user->language) ? t('DEFAULT') : $user->language,
    '%user_timezone' => empty($user->timezone) ? '0' : "$user->timezone",
    '%user_signature' => $user->signature,
    '%google_user' => "http://www.google.com/search?q=%22$user->mail%22",
    '%yahoo_user' => "http://search.yahoo.com/search/?p=%22$user->mail%22",
  );
}

First I tried adding:
'%something_extra' => $user->profile_name,
While also adding the token %something_extra into the body of the email on the Administer>Advanced User page.
But that didn't work....

I've fussed with a number of things, such as putting profile_load_profile($user) before the array... but still no go.

If I do a simple test, with:

'%something_extra' => "some extra text",

Then that actually works... so it appears I'm not able to pull the user profile data correctly.

I've also read in some places that the profile fields can be read from the $account variable... but how do I get the $account for a specific user id ???

Other considerations -- at this point in the account creation process does the Profile actually exist? Or is the notification email being sent before the profile entry is created?

Thanks for any help,

-Chris

#1

rares - June 30, 2009 - 18:24

I think that the $user object passed to advuser_user (and then to _advuser_get_variables) does not contain profile data.
Moreover, profile_load_profile probably fails because the profile fields have not yet been saved. They are probably still in the $edit array.

If you look at the documentation for hook_user, it says for $op:
"insert": The user account is being added. The module should save its custom additions to the user object into the database and set the saved fields to NULL in $edit.
"after_update": The user object has been updated and changed. Use this if (probably along with 'insert') if you want to reuse some information from the user object.

My impression is that to achieve what you want, the module needs to use the after_update op for inserts too, and to look at some part of the user object (perhaps $user->created == $user->access, if they exist) to see if it's new or not.
If this works for you maybe we can create a patch and help the contributor take the next steps to adding profile tokens (speaking of this, is anyone familiar with the token module API, maybe it can be integrated?)

#2

beltofte - July 1, 2009 - 13:31

About the missing profile that has not been stored yet. A solution could be to change the weight value in the system table for the advuser module, so it will be run after the profile module. For example change the weight value to 1.

#3

earnie - July 1, 2009 - 19:06

@beltofte: That would be an easier change. I'll work on it.

 
 

Drupal is a registered trademark of Dries Buytaert.