Index: token.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v retrieving revision 1.49 diff -u -p -r1.49 token.module --- token.module 16 Nov 2010 04:18:59 -0000 1.49 +++ token.module 17 Nov 2010 23:11:32 -0000 @@ -471,6 +471,30 @@ function token_element_validate_token_co /** * Implements hook_form_FORM_ID_alter(). * + * Alters the configure action form to add token context validation and + * adds the token tree for a better token UI and selection. + */ +function token_form_system_actions_configure_alter(&$form, $form_state) { + $actions_map = actions_actions_map(actions_list()); + $action = $actions_map[$form['actions_action']['#value']]; + + switch ($action['callback']) { + case 'system_message_action': + case 'system_send_email_action': + case 'system_goto_action': + $form['token_tree'] = array( + '#theme' => 'token_tree', + '#token_types' => 'all', + '#weight' => 100, + ); + // @todo Add token validation to the action fields that can use tokens. + break; + } +} + +/** + * Implements hook_form_FORM_ID_alter(). + * * Alters the user e-mail fields to add token context validation and * adds the token tree for a better token UI and selection. */ Index: token_actions.info =================================================================== RCS file: token_actions.info diff -N token_actions.info --- token_actions.info 11 Jul 2009 18:33:46 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,6 +0,0 @@ -; $Id: token_actions.info,v 1.2 2009/07/11 18:33:46 eaton Exp $ -name = Token actions -description = Provides enhanced versions of core Drupal actions using the Token module. -requirements[] = token -files[] = token_actions.module -core = 7.x Index: token_actions.module =================================================================== RCS file: token_actions.module diff -N token_actions.module --- token_actions.module 19 Sep 2010 19:39:56 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,211 +0,0 @@ - array( - 'type' => 'system', - 'label' => t('Display a tokenized message to the user'), - 'configurable' => TRUE, - 'hooks' => array( - 'nodeapi' => array('view', 'insert', 'update', 'delete'), - 'comment' => array('view', 'insert', 'update', 'delete'), - 'user' => array('view', 'insert', 'update', 'delete', 'login'), - 'taxonomy' => array('insert', 'update', 'delete'), - ), - ), - 'token_actions_send_email_action' => array( - 'type' => 'system', - 'label' => t('Send tokenized e-mail'), - 'configurable' => TRUE, - 'hooks' => array( - 'nodeapi' => array('view', 'insert', 'update', 'delete'), - 'comment' => array('view', 'insert', 'update', 'delete'), - 'user' => array('view', 'insert', 'update', 'delete', 'login'), - 'taxonomy' => array('insert', 'update', 'delete'), - ) - ), - 'token_actions_goto_action' => array( - 'type' => 'system', - 'label' => t('Redirect to a tokenized URL'), - 'configurable' => TRUE, - 'hooks' => array( - 'nodeapi' => array('view', 'insert', 'update', 'delete'), - 'comment' => array('view', 'insert', 'update', 'delete'), - 'user' => array('view', 'insert', 'update', 'delete', 'login'), - ) - ) - ); -} - -/** - * Return a form definition so the Send email action can be configured. - * - * @param $context - * Default values (if we are editing an existing action instance). - * @return - * Form definition. - */ -function token_actions_send_email_action_form($context) { - // Set default values for form. - if (!isset($context['recipient'])) { - $context['recipient'] = ''; - } - if (!isset($context['subject'])) { - $context['subject'] = ''; - } - if (!isset($context['message'])) { - $context['message'] = ''; - } - - $form['recipient'] = array( - '#type' => 'textfield', - '#title' => t('Recipient'), - '#default_value' => $context['recipient'], - '#size' => '20', - '#maxlength' => '254', - '#description' => t('The email address to which the message should be sent.'), - ); - $form['subject'] = array( - '#type' => 'textfield', - '#title' => t('Subject'), - '#default_value' => $context['subject'], - '#size' => '20', - '#maxlength' => '254', - '#description' => t('The subject of the message.'), - ); - $form['message'] = array( - '#type' => 'textarea', - '#title' => t('Message'), - '#default_value' => $context['message'], - '#cols' => '80', - '#rows' => '20', - '#description' => t('The message that should be sent.'), - ); - - $form['help'] = array( - '#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#title' => t('Placeholder tokens'), - '#description' => t("The following placeholder tokens can be used in to generate the URL path. Some tokens may not be available, depending on the context in which the action is triggered."), - ); - - $form['help']['tokens'] = array( - '#markup' => '' . t('Token help is not yet available.') . '', - ); - - return $form; -} - -function token_actions_send_email_action_submit($form, $form_state) { - $form_values = $form_state['input']; - // Process the HTML form to store configuration. The keyed array that - // we return will be serialized to the database. - $params = array( - 'recipient' => $form_values['recipient'], - 'subject' => $form_values['subject'], - 'message' => $form_values['message'], - ); - return $params; -} - -/** - * Implementation of a configurable Drupal action. - * Sends an email. - */ -function token_actions_send_email_action($object, $context) { - $from = variable_get('site_mail', ini_get('sendmail_from')); - $recipient = token_replace_all($context['recipient'], $context); - - $subject = token_replace($context['subject'], $context); - $subject = str_replace(array("\r", "\n"), '', $subject); - $message = token_replace($context['message'], $context); - - $body = drupal_html_to_text($message); - - if (drupal_mail('action_send_email', $recipient, $subject, $body, $from)) { - watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient)); - } - else { - watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient)); - } -} - -function token_actions_message_action_form($context) { - $form['message'] = array( - '#type' => 'textarea', - '#title' => t('Message'), - '#default_value' => isset($context['message']) ? $context['message'] : '', - '#required' => TRUE, - '#rows' => '8', - '#description' => t('The message to be displayed to the current user.'), - ); - - $form['help'] = array( - '#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#title' => t('Placeholder tokens'), - '#description' => t("The following placeholder tokens can be used in the custom message text. Some tokens may not be available, depending on the context in which the action is triggered."), - ); - - $form['help']['tokens'] = array( - '#markup' => '' . t('Token help is not yet available.') . '', - ); - - return $form; -} - -function token_actions_message_action_submit($form, $form_state) { - return array('message' => $form_state['input']['message']); -} - -/** - * Implementation of a configurable Drupal action. - * Sends a configurable message to the current user's screen. - */ -function token_actions_message_action(&$object, $context = array()) { - $context['message'] = token_replace($context['message'], $context); - drupal_set_message($context['message']); -} - -/** - * Implementation of a configurable Drupal action. - * Redirect user to a URL. - */ -function token_actions_goto_action_form($context) { - $form['url'] = array( - '#type' => 'textfield', - '#title' => t('URL'), - '#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like http://drupal.org.'), - '#default_value' => isset($context['url']) ? $context['url'] : '', - '#required' => TRUE, - ); - $form['help'] = array( - '#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#title' => t('Placeholder tokens'), - '#description' => t("The following placeholder tokens can be used in the URL path. Some tokens may not be available, depending on the context in which the action is triggered."), - ); - - $form['help']['tokens'] = array( - '#markup' => '' . t('Token help is not yet available.') . '', - ); - - return $form; -} - -function token_actions_goto_action_submit($form, $form_state) { - return array( - 'url' => $form_state['values']['url'] - ); -} - -function token_actions_goto_action($object, $context) { - drupal_goto(token_replace_multiple($context['url'], $context)); -}