diff --git a/message_notify.rules.inc b/message_notify.rules.inc index 7696978..049e996 100644 --- a/message_notify.rules.inc +++ b/message_notify.rules.inc @@ -14,70 +14,49 @@ function message_notify_rules_action_info() { $items = array(); - // Define an action for each notifier plugin. - $plugins = message_notify_get_notifiers(); - - foreach ($plugins as $name => $plugin) { - $action = array( - 'label' => $plugin['description'], - 'group' => t('Message notify'), - 'named parameter' => TRUE, - 'parameter' => array( - 'message' => array( - 'type' => 'message', - 'label' => t('Message'), - 'description' => t('The message to be processed and sent using Message notify.'), - ), - 'save_on_fail' => array( - 'type' => 'boolean', - 'label' => t('Save on fail'), - 'description' => t('Save message if sending failed.'), - 'default value' => TRUE, - 'optional' => TRUE, - 'restriction' => 'input', - ), - 'save_on_success' => array( - 'type' => 'boolean', - 'label' => t('Save on success'), - 'description' => t('Save message if sending succeeded.'), - 'default value' => TRUE, - 'optional' => TRUE, - 'restriction' => 'input', - ), - // @todo This is needed by [only] the 'email' plugin. See note below. - 'mail' => array( - 'type' => 'text', - 'label' => t('The recipient of the email'), - 'description' => t('The recipient of the email. If left empty, the mail will be sent to the author of the message.'), - 'default value' => FALSE, - 'allow null' => TRUE, - 'optional' => TRUE, - ), + $items['message_notify_process'] = array( + 'label' => t('Send Message with Message notify'), + 'group' => t('Message notify'), + 'parameter' => array( + 'message' => array( + 'type' => 'message', + 'label' => t('Message'), + 'description' => t('The message to be processed and sent using Message notify.'), ), - 'base' => 'message_notify_rules_process_plugin', - ); - - // @todo Add parameters based on the options defined for the plugin. - - // Add parameters to select the rendered field for each view mode the - // plugin defines. - foreach ($plugin['view_modes'] as $view_mode => $view_mode_definition) { - $action['parameter']['rendered_field__' . $view_mode] = array( - 'type' => 'token', - 'label' => t('Rendered @view_mode', array( - '@view_mode' => $view_mode_definition['label'], - )), - 'description' => t('The field to save the @view_mode rendering.', array( - '@view_mode' => $view_mode_definition['label'], - )), + 'save_on_fail' => array( + 'type' => 'boolean', + 'label' => t('Save on fail'), + 'description' => t('Save message if sending failed.'), + 'default value' => TRUE, + 'optional' => TRUE, + 'restriction' => 'input', + ), + 'save_on_success' => array( + 'type' => 'boolean', + 'label' => t('Save on success'), + 'description' => t('Save message if sending succeeded.'), + 'default value' => TRUE, + 'optional' => TRUE, + 'restriction' => 'input', + ), + 'mail' => array( + 'type' => 'text', + 'label' => t('The recipient of the email'), + 'description' => t('The recipient of the email. If left empty, the mail will be sent to the author of the message. Note that its value will be considered only if you have Email selected as notify plugin.'), 'default value' => FALSE, + 'allow null' => TRUE, 'optional' => TRUE, - 'options list' => 'message_notify_field_text_list', - ); - } - - $items['message_notify_process__' . $name] = $action; - } + ), + 'plugin' => array( + 'type' => 'text', + 'label' => t('Notify plugin'), + 'description' => t('Plugin that will be used for message notification'), + 'default value' => 'email', + 'options list' => 'message_notify_plugin_options', + ), + ), + 'base' => 'message_notify_rules_process', + ); return $items; } @@ -88,63 +67,30 @@ function message_notify_rules_action_info() { * This callback is used to handle the Rules action for all message notify * plugins. */ -function message_notify_rules_process_plugin($arguments, $element, $name) { - - // Determine which message_notify plugin should be used for this action. - $action_name = $element->getElementName(); - list($prefix, $notify_plugin) = explode('__', $action_name, 2); - - // Get the plugin definition for default options, etc. - $plugins = message_notify_get_notifiers(); - $plugin = $plugins[$notify_plugin]; - - // Extract the standard parameters from the arguments array. - $message = $arguments['message']; - $save_on_fail = $arguments['save_on_fail']; - $save_on_success = $arguments['save_on_success']; - $mail = $arguments['mail']; - - // Use the default values for the plugin option. - $options = $plugin['options']; +function message_notify_rules_process(Message $message, $save_on_fail, $save_on_success, $mail = FALSE, $plugin) { + $options = array( + 'save on fail' => $save_on_fail, + 'save on success' => $save_on_success, + ); - // Extract any rendered field parameters and push them into the options we'll - // pass through for the plugin. - foreach ($arguments as $name => $value) { - if (0 === strpos('rendered_field__', $name)) { - list($prefix, $view_mode) = explode('__', $name, 2); - $options['rendered fields'][$view_mode] = $value; - } - } - - // @todo This is needed by the 'email' notification plugin. It should not be - // hardcoded. See message_notify_rules_action_info() above. if ($mail) { $options['mail'] = str_replace(array("\r", "\n"), '', $mail); } - message_notify_send_message($message, $options, $notify_plugin); + message_notify_send_message($message, $options, $plugin); } /** - * Options list; Return the text field attached to the selected message + * Return list of all available message notification plugins. + * + * @return array + * Message notify plugins. */ -function message_notify_field_text_list() { - $options = array(FALSE => '- ' . t('None') . ' -'); - - foreach (field_info_instances('message') as $message_type => $instances) { - foreach ($instances as $field_name => $instance) { - if (!empty($options[$field_name])) { - // Field is already in the options array. - continue; - } - $field = field_info_field($field_name); - if (!in_array($field['type'], array('text', 'text_long', 'text_with_summary'))) { - // Field is not a text field. - continue; - } +function message_notify_plugin_options() { + $plugins = message_notify_get_notifiers(); - $options[$field_name] = $instance['label']; - } + foreach ($plugins as $name => $plugin) { + $options[$name] = $plugin['title']; } return $options;