? 944268-rcn-token-cleanup-D7.patch
Index: role_change_notify.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/role_change_notify/role_change_notify.install,v
retrieving revision 1.8
diff -u -p -r1.8 role_change_notify.install
--- role_change_notify.install	20 Feb 2010 23:59:58 -0000	1.8
+++ role_change_notify.install	17 Oct 2010 18:59:35 -0000
@@ -30,18 +30,18 @@ function role_change_notify_uninstall() 
 }
 
 /**
- * Attempt to update existing [role] or [role_changed] to new format.
+ * Attempt to update existing [role] or [role-changed] to new format.
  */
 function role_change_notify_update_7100() {
   $subject = variable_get('role_change_notify_role_added_subject', "");
   $body = variable_get('role_change_notify_role_added_body', "");
   if (!empty($subject)) {
-    $subject = preg_replace('/(\[role\]|\[role_changed\])/', '[user:role_changed]', $subject);
+    $subject = preg_replace('/(\[role\]|\[role_changed\])/', '[user:role-changed]', $subject);
   }
   if (!empty($body)) {
-    $body = preg_replace('/(\[role\]|\[role_changed\])/', '[user:role_changed]', $body);
+    $body = preg_replace('/(\[role\]|\[role_changed\])/', '[user:role-changed]', $body);
   }
   variable_set('role_change_notify_role_added_subject', $subject);
   variable_set('role_change_notify_role_added_body', $body);
-  return(t('Role Change Notify updated the [user:role_changed] token but other tokens may still be obsolete in various messages. Please check your messages in <a href="@rcn_link">Role Change Notification admin</a> and in any actions that use the Role Change Notification triggers.'));
-}
\ No newline at end of file
+  return(t('Role Change Notify updated the [user:role-changed] token but other tokens may still be obsolete in various messages. Please check your messages in <a href="@rcn_link">Role Change Notification admin</a> and in any actions that use the Role Change Notification triggers.'));
+}
Index: role_change_notify.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/role_change_notify/role_change_notify.module,v
retrieving revision 1.11
diff -u -p -r1.11 role_change_notify.module
--- role_change_notify.module	10 Mar 2010 18:47:42 -0000	1.11
+++ role_change_notify.module	17 Oct 2010 18:59:35 -0000
@@ -7,8 +7,8 @@
  *
  */
 
-define('RCN_SUBJECT_DEFAULT', t('Role [user:role_changed] added for [user:name] at [site:name]'));
-define('RCN_BODY_DEFAULT', t("[user:name],\n\nThe role \"[user:role_changed]\" has been added to your account at  [site:name].\n\nYou may now use the associated privileges."));
+define('RCN_SUBJECT_DEFAULT', t('Role [user:role-changed] added for [user:name] at [site:name]'));
+define('RCN_BODY_DEFAULT', t("[user:name],\n\nThe role \"[user:role-changed]\" has been added to your account at  [site:name].\n\nYou may now use the associated privileges."));
 /**
  * Print module description on module activation page
  */
@@ -27,8 +27,6 @@ function role_change_notify_help($path, 
       }
       $output .= '<p>' . t('This page allows you to configure whether automatic emails should be set to users when a new role is assigned to them. You define if an email should be sent for each role type, and if so, you define what the subject and body of the resulting email will be.') . '</p>'
       . '<p>' . t('For any of the settings below, you can use placeholders which will be substituted with the current values for the user, role, and site.') . ' ';
-      // TODO: Find out what the standard tokens are!
-      $output .= t('The standard Drupal tokens are available for use, including, among others:') . '[user:role_changed] (the role that was added or removed), [user:name] (username), [user:uid], [site:name], [site:url], [site:uri_brief], [user:mail], [site:date], [site:login_uri], [user:account-edit], [user:role_changed].';
       $output .= '</p>';
       $output .= "<p>" . t("If the Triggers module is enabled, this module also provides Role Change Notification triggers on the
         <a href='!link'>User Triggers Page</a> that can be fired when a role is added or removed.",
@@ -112,6 +110,7 @@ function role_change_notify_settings_for
     '#default_value' => variable_get('role_change_notify_role_added_subject', RCN_SUBJECT_DEFAULT),
     '#size' => 72,
     '#maxlength' => 200,
+    '#token_types' => array('user'),
   );
   $form['role_change_notify_role_added_body'] = array(
     '#type' => 'textarea',
@@ -120,20 +119,24 @@ function role_change_notify_settings_for
     '#cols' => 72,
     '#rows' => 10,
     '#description' => '',
+    '#token_types' => array('user'),
   );
+
   if (module_exists('token')) {
     $form['view']['token_help'] = array(
       '#title' => t('Replacement patterns'),
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
       '#collapsed' => TRUE,
-      '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
     );
-
     $form['view']['token_help']['help'] = array(
-      '#value' => theme('token_help', 'user'),
+      '#theme' => 'token_tree',
+      '#token_types' => array('user'),
     );
+    $form['role_change_notify_role_added_subject']['#element_validate'] = array('token_element_validate_token_context');
+    $form['role_change_notify_role_added_body']['#element_validate'] = array('token_element_validate_token_context');
   }
+
   return system_settings_form($form);
 }
 
@@ -248,5 +251,3 @@ function role_change_notify_mail($key, &
     $message['headers'] = array_merge($message['headers'], $params['context']['headers']);
   }
 }
-
-
Index: role_change_notify.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/role_change_notify/role_change_notify.test,v
retrieving revision 1.2
diff -u -p -r1.2 role_change_notify.test
--- role_change_notify.test	10 Mar 2010 18:47:42 -0000	1.2
+++ role_change_notify.test	17 Oct 2010 18:59:35 -0000
@@ -59,7 +59,7 @@ class RoleChangeNotifyTestCase extends T
     $this->drupalPost("admin/people/role_change_notify", $edit, t('Save configuration'));
 
     // Create an advanced system_message_action to issue a message.
-    $message = "Message: Role added=[user:role_changed] User=[user:name]";
+    $message = "Message: Role added=[user:role-changed] User=[user:name]";
     $actions_edit = array(
       'actions_label' => 'RCN Add Role',
       'message' => $message,
@@ -82,7 +82,7 @@ class RoleChangeNotifyTestCase extends T
 
 
     // Create a system email message that will be sent when a role is removed.
-    $message = "Message: Role removed=[user:role_changed] User=[user:name]";
+    $message = "Message: Role removed=[user:role-changed] User=[user:name]";
     $actions_edit = array(
       'actions_label' => 'RCN Remove Role',
       'recipient' => 'nobody@example.com',
@@ -161,5 +161,3 @@ class RoleChangeNotifyTestCase extends T
     $this->assertText(t("The update has been performed"));
   }
 }
-
-
Index: role_change_notify.tokens.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/role_change_notify/role_change_notify.tokens.inc,v
retrieving revision 1.1
diff -u -p -r1.1 role_change_notify.tokens.inc
--- role_change_notify.tokens.inc	20 Feb 2010 23:59:58 -0000	1.1
+++ role_change_notify.tokens.inc	17 Oct 2010 18:59:35 -0000
@@ -7,25 +7,31 @@
  *
  */
 
-
 /**
- * Implements hook_token_info() to tell about what tokens it offers.
- * @return array
- *   the array structure required by the hook.
+ * Implements hook_token_info().
  */
 function role_change_notify_token_info() {
-  $tokens['role_changed'] = array(
+  $info['tokens']['user']['role-changed'] = array(
     'name' => t('Role Changed'),
     'description' => t('The role that was changed for the user'),
   );
-  return array('user' => $tokens);
+  return $info;
 }
 
 /**
- * Implements hook_tokens to provide the user:role_changed token.
+ * Implements hook_tokens().
  */
 function role_change_notify_tokens($type, $tokens, array $data = array(), array $options = array()) {
-  if ($type == 'user' && !empty($tokens['role_changed']) && !empty($data['user']->role_changed)) {
-    return array('[user:role_changed]' => $data['user']->role_changed);
+  $replacements = array();
+  $sanitize = !empty($options['sanitize']);
+
+  if ($type == 'user' && !empty($data['user'])) {
+    $account = $data['user'];
+
+    if (isset($tokens['role-changed']) && !empty($account->role_changed)) {
+      $replacements[$tokens['role-changed']] = $sanitize ? check_plain($account->role_changed) : $account->role_changed;
+    }
   }
+
+  return $replacements;
 }
