You are here

function views_send_form_alter in Views Send 6

Same name and namespace in other branches
  1. 7 views_send.module \views_send_form_alter()

Implementation of hook_form_alter().

We want to alter the confirmation form, just before processing the action, so the the user can preview the whole message berore sending it.

See also

http://api.drupal.org/api/function/hook_form_alter/6

File

./views_send.module, line 454
The Views Send module.

Code

function views_send_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'views_bulk_operations_form') === 0 && $form_state['values']['step'] >= VBO_STEP_CONFIG && $form_state['storage']['operation']['key'] == 'views_send_mail_action') {
    drupal_set_title(t('Review and confirm the message that is about to be sent'));
    drupal_add_css(drupal_get_path('module', 'views_send') . '/views_send.css');
    $args =& $form_state['storage']['operation_arguments'];

    // Drop the confirmation form warning message.
    unset($form['description']);
    $form['#attributes']['class'] .= ' views-send-preview';
    $form['from'] = array(
      '#type' => 'item',
      '#title' => t('From'),
      '#value' => '<div class="views-send-preview-value">' . (empty($args['views_send_from_name']) ? $args['views_send_from_mail'] : $args['views_send_from_name'] . check_plain(' <' . $args['views_send_from_mail'] . '>')) . '</div>',
    );
    $recipients = array();
    foreach ($form_state['storage']['selection'] as $oid => $row) {
      $email = trim(_views_send_get_from_views_result($row, $args["views_send_to_mail"], 'email'));
      $name = _views_send_get_from_views_result($row, $args["views_send_to_name"]);
      $recipients[] = check_plain(empty($name) ? $email : $name . ' <' . $email . '>');
    }
    $preview_to = '';
    if ($form_state['storage']['selectall'] && empty($recipients)) {
      $preview_to = t('- All -');
    }
    else {
      $preview_to = implode(', ', $recipients);
    }
    $form['to'] = array(
      '#type' => 'item',
      '#title' => t('To'),
      '#value' => '<div id="views-send-preview-to" class="views-send-preview-value">' . $preview_to . '</div>',
    );
    $form['subject'] = array(
      '#type' => 'item',
      '#title' => t('Subject'),
      '#value' => '<div class="views-send-preview-value">' . $args['views_send_subject'] . '</div>',
    );
    if ($args['views_send_message_format'] == VIEWS_SEND_FORMAT_PLAIN) {
      $message = '<div style="white-space: pre;">' . $args['views_send_message'] . '</div>';
    }
    else {
      $message = check_markup($args['views_send_message'], $args['views_send_message_format']);
    }
    $form['message'] = array(
      '#type' => 'item',
      '#title' => t('Message'),
      '#value' => '<div id="views-send-preview-message" class="views-send-preview-value">' . $message . '</div>',
    );
    $headers = array();
    foreach (_views_send_headers($args['views_send_receipt'], $args['views_send_priority'], $args['views_send_from_mail'], $args['views_send_headers']) as $key => $value) {
      $headers[] = $key . ': ' . $value;
    }
    $form['headers'] = array(
      '#type' => 'item',
      '#title' => t('Headers'),
      '#value' => '<div id="views-send-preview-headers" class="views-send-preview-value">' . implode('<br />', $headers) . '</div>',
    );
    if (VIEWS_SEND_MIMEMAIL && !empty($args['views_send_attachments']) && user_access('allow attachments with views_send')) {
      foreach ($args['views_send_attachments'] as $attachment) {
        $attachments[] = $attachment['filename'];
      }
      $form['attachments'] = array(
        '#type' => 'item',
        '#title' => t('Attachments'),
        '#value' => '<div id="views-send-preview-attachments" class="views-send-preview-value">' . implode('<br />', $attachments) . '</div>',
      );
    }
    $form['actions']['#weight'] = 100;
  }
}