Thanks for the great module.

I am new to Drupal development, but I wanted to customize this module to include support for replacement patterns from the profile module (I wanted to address the email to $user->profile_firstname instead of $user->name). So I added this to the end of the function _role_change_notify_get_variables just before returning $variables:

if ($user->uid && module_exists('profile')) {
  profile_load_profile($user);
  $role_change_user_keys = array_keys(get_object_vars($user));
  foreach($role_change_user_keys as $keys){
    if(strpos($keys, 'profile_') === 0){
      $variables['%'.$keys] = $user->$keys;
    }
  }
}

Then you can use %profile_whatever in your subject and body.

Hopefully my explanation is clear. I am a Windows user, and I could not figure out how to create a patch file, but I will keep trying. Can anyone else test this? Did I do it right?

Thanks

Comments

rfay’s picture

Status: Needs review » Needs work

The first rule of drupal development is "Don't hack core".

The second rule is "Don't hack contrib, because then you own custom code that only you can maintain. You'll never be able to update."

Please learn how to create patches, and offer features if you will. http://drupal.org/patch.

On windows, I used to very happily use Cygwin for all such things. Other possibilities are offered there.

bander2’s picture

StatusFileSize
new706 bytes

Yeah, I've broken those rules 100 times, I see the light now:) After upgrading from 5.x to 6.x I am trying to do things the right way.

So, here's the patch.

rfay’s picture

I think these things will need to be improved:

1. The items need to have check_plain() run on them, since they're from untrusted, user data.
2. You'll want the list of available tokens to show up in the list of replaceable tokens that can be used (in the description, I think it is)
3. You may want to actually consider just implementing support for the token module - it's a lot of fun and gives far more bang for the buck.

Thanks for this! And you figured out patching!

bander2’s picture

StatusFileSize
new6.76 KB

OK, I have check_plain() on the user data. I modified the description text to show the new replacement values. Actually, if the token module is enabled, I forgo this text in favor of hook_token_list(). And I implemented token module support.

I also changed the replacement format from %variable to [variable] . This is mostly because that is how it shows up in theme('token_help') and I didn't want to confuse users. I also changed some of the replacement patters to match the Token version so that there is less (hopefully, no) confusing overlap between the patters provided by default and those provided by the token module ('username' changed to 'name', etc.).

rfay’s picture

Thanks for doing this. I will try to take a look at it this week.
-Randy

rfay’s picture

Title: Add support for profile tokens » Add support for token module, and add profile tokens
Status: Needs work » Fixed

This is in 6.x-2.0-beta1

Thanks for the patch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.