You are here

function views_send_config_form in Views Send 7

Same name and namespace in other branches
  1. 8 views_send.module \views_send_config_form()

Multistep form callback for the "configure" step.

@TODO: Hide "Sender" (from) if Mandrill is used.

2 string references to 'views_send_config_form'
views_send_form_back_submit in ./views_send.module
Submit handler that handles back buttons.
views_send_form_submit in ./views_send.module
Submit handler for all steps of the Views Send multistep form.

File

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

Code

function views_send_config_form($form, &$form_state, $view, $output) {
  if (!empty($form_state['configuration'])) {

    // Values entered in the "config" step.
    $config = $form_state['configuration'];
  }
  $display = $view->name . ':' . $view->current_display;
  $form['display'] = array(
    '#type' => 'value',
    '#value' => $display,
  );
  $form['from'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sender'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['from']['views_send_from_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Sender\'s name'),
    '#description' => t("Enter the sender's human readable name."),
    '#default_value' => isset($config['views_send_from_name']) ? $config['views_send_from_name'] : variable_get('views_send_from_name_' . $display, variable_get('site_name', '')),
    '#maxlen' => 255,
  );
  $form['from']['views_send_from_mail'] = array(
    '#type' => 'textfield',
    '#title' => t('Sender\'s e-mail'),
    '#description' => t("Enter the sender's e-mail address."),
    '#required' => TRUE,
    '#default_value' => isset($config['views_send_from_mail']) ? $config['views_send_from_mail'] : variable_get('views_send_from_mail_' . $display, variable_get('site_mail', ini_get('sendmail_from'))),
    '#maxlen' => 255,
  );
  $fields = _views_send_get_fields_and_tokens($view, 'fields');
  $tokens = _views_send_get_fields_and_tokens($view, 'tokens');
  $fields_name_text = _views_send_get_fields_and_tokens($view, 'fields_name_text');
  $fields_options = array_merge(array(
    '' => '<' . t('select') . '>',
  ), $fields);
  $form['views_send_tokens'] = array(
    '#type' => 'value',
    '#value' => $tokens,
  );
  $form['to'] = array(
    '#type' => 'fieldset',
    '#title' => t('Recipients'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['to']['views_send_to_name'] = array(
    '#type' => 'select',
    '#title' => t('Field used for recipient\'s name'),
    '#description' => t('Select which field from the current view will be used as recipient\'s name.'),
    '#options' => $fields_options,
    '#default_value' => isset($config['views_send_to_name']) ? $config['views_send_to_name'] : variable_get('views_send_to_name_' . $display, ''),
  );
  $form['to']['views_send_to_mail'] = array(
    '#type' => 'select',
    '#title' => t('Field used for recipient\'s e-mail'),
    '#description' => t('Select which field from the current view will be used as recipient\'s e-mail.'),
    '#options' => $fields_options,
    '#default_value' => isset($config['views_send_to_mail']) ? $config['views_send_to_mail'] : variable_get('views_send_to_mail_' . $display, ''),
    '#required' => TRUE,
  );
  $form['mail'] = array(
    '#type' => 'fieldset',
    '#title' => t('E-mail content'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['mail']['views_send_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#description' => t('Enter the e-mail\'s subject. You can use tokens in the subject.'),
    '#maxlen' => 255,
    '#required' => TRUE,
    '#default_value' => isset($config['views_send_subject']) ? $config['views_send_subject'] : variable_get('views_send_subject_' . $display, ''),
  );
  $form['mail']['views_send_message'] = array(
    '#type' => 'text_format',
    '#title' => t('Message'),
    '#description' => t('Enter the body of the message. You can use tokens in the message.'),
    '#required' => TRUE,
    '#rows' => 10,
  );
  if (isset($config['views_send_message']['value'])) {
    $form['mail']['views_send_message'] += array(
      '#format' => $config['views_send_message']['format'],
      '#default_value' => $config['views_send_message']['value'],
    );
  }
  else {
    $saved_message = variable_get('views_send_message_' . $display);
    $form['mail']['views_send_message'] += array(
      '#format' => isset($saved_message['format']) ? $saved_message['format'] : filter_fallback_format(),
      '#default_value' => isset($saved_message['value']) ? $saved_message['value'] : '',
    );
  }
  $form['mail']['token'] = array(
    '#type' => 'fieldset',
    '#title' => t('Tokens'),
    '#description' => t('You can use the following tokens in the subject or message.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  if (!module_exists('token')) {
    $form['mail']['token']['tokens'] = array(
      '#markup' => theme('views_send_token_help', $fields_name_text),
    );
  }
  else {
    $form['mail']['token']['views_send'] = array(
      '#type' => 'fieldset',
      '#title' => t('Views Send specific tokens'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['mail']['token']['views_send']['tokens'] = array(
      '#markup' => theme('views_send_token_help', $fields_name_text),
    );
    $form['mail']['token']['general'] = array(
      '#type' => 'fieldset',
      '#title' => t('General tokens'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $token_types = array(
      'site',
      'user',
      'node',
      'current-date',
    );
    $form['mail']['token']['general']['tokens'] = array(
      '#markup' => theme('token_tree', array(
        'token_types' => $token_types,
        'show_restricted' => TRUE,
      )),
    );
  }
  if (VIEWS_SEND_MIMEMAIL && user_access('attachments with views_send')) {

    // set the form encoding type
    $form['#attributes']['enctype'] = "multipart/form-data";

    // add a file upload file
    $form['mail']['views_send_attachments'] = array(
      '#type' => 'file',
      '#title' => t('Attachment'),
      '#description' => t('NB! The attached file is stored once per recipient in the database if you aren\'t sending the message directly.'),
    );
  }
  $form['additional'] = array(
    '#type' => 'fieldset',
    '#title' => t('Additional e-mail options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['additional']['views_send_priority'] = array(
    '#type' => 'select',
    '#title' => t('Priority'),
    '#options' => array(
      VIEWS_SEND_PRIORITY_NONE => t('none'),
      VIEWS_SEND_PRIORITY_HIGHEST => t('highest'),
      VIEWS_SEND_PRIORITY_HIGH => t('high'),
      VIEWS_SEND_PRIORITY_NORMAL => t('normal'),
      VIEWS_SEND_PRIORITY_LOW => t('low'),
      VIEWS_SEND_PRIORITY_LOWEST => t('lowest'),
    ),
    '#description' => t('Note that e-mail priority is ignored by a lot of e-mail programs.'),
    '#default_value' => isset($config['views_send_priority']) ? $config['views_send_priority'] : variable_get('views_send_priority_' . $display, 0),
  );
  $form['additional']['views_send_receipt'] = array(
    '#type' => 'checkbox',
    '#title' => t('Request receipt'),
    '#default_value' => isset($config['views_send_receipt']) ? $config['views_send_receipt'] : variable_get('views_send_receipt_' . $display, 0),
    '#description' => t('Request a Read Receipt from your e-mails. A lot of e-mail programs ignore these so it is not a definitive indication of how many people have read your message.'),
  );
  $form['additional']['views_send_headers'] = array(
    '#type' => 'textarea',
    '#title' => t('Additional headers'),
    '#description' => t("Additional headers to be send with the message. You'll have to enter one per line. Example:<pre>Reply-To: noreply@example.com\nX-MyCustomHeader: Whatever</pre>"),
    '#rows' => 4,
    '#default_value' => isset($config['views_send_headers']) ? $config['views_send_headers'] : variable_get('views_send_headers_' . $display, ''),
  );
  $form['views_send_direct'] = array(
    '#type' => 'checkbox',
    '#title' => t('Send the message directly using the Batch API.'),
    '#default_value' => isset($config['views_send_direct']) ? $config['views_send_direct'] : variable_get('views_send_direct_' . $display, TRUE),
  );
  $form['views_send_carbon_copy'] = array(
    '#type' => 'checkbox',
    '#title' => t('Send a copy of the message to the sender.'),
    '#default_value' => isset($config['views_send_carbon_copy']) ? $config['views_send_carbon_copy'] : variable_get('views_send_carbon_copy_' . $display, TRUE),
  );
  $form['views_send_remember'] = array(
    '#type' => 'checkbox',
    '#title' => t('Remember these values for the next time a mass mail is sent. (The values are not stored per user.)'),
    '#default_value' => variable_get('views_send_remember_' . $display, FALSE),
  );
  $query = drupal_get_query_parameters($_GET, array(
    'q',
  ));
  $form['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
    '#weight' => 999,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Next'),
    '#validate' => array(
      'views_send_config_form_validate',
    ),
    '#submit' => array(
      'views_send_form_submit',
    ),
    '#suffix' => l(t('Cancel'), $view
      ->get_url(), array(
      'query' => $query,
    )),
  );
  return $form;
}