You are here

function sparkpost_admin_settings in Sparkpost email 7.2

Same name and namespace in other branches
  1. 7 sparkpost.admin.inc \sparkpost_admin_settings()

Administrative settings.

Parameters

array $form: Form render array.

array $form_state: Array containing form state values.

Return value

array An array containing form items to place on the module settings page.

1 string reference to 'sparkpost_admin_settings'
sparkpost_menu in ./sparkpost.module
Implements hook_menu().

File

./sparkpost.admin.inc, line 19
Admin callbacks.

Code

function sparkpost_admin_settings($form, &$form_state) {
  $key = variable_get('sparkpost_api_key');
  $form['sparkpost_api_key'] = array(
    '#title' => t('Sparkpost API Key'),
    '#type' => 'textfield',
    '#description' => t('Create or grab your API key from the !link.', array(
      '!link' => l(t('Sparkpost settings'), 'https://app.sparkpost.com/account/credentials'),
    )),
    '#default_value' => $key,
  );
  $library_exists = class_exists('\\SparkPost\\SparkPost');
  if (!$library_exists) {
    drupal_set_message(t('The Sparkpost PHP library is not installed. Please see installation directions in README.md'), 'warning');
  }
  if ($key && $library_exists) {
    $mailsystem_config_keys = mailsystem_get();
    $in_use = FALSE;
    $usage_rows = array();
    foreach ($mailsystem_config_keys as $key => $sys) {
      if ($sys === 'SparkpostMailSystem' && $key != 'sparkpost_test') {
        $in_use = TRUE;
        $usage_rows[] = array(
          $key,
          $sys,
        );
      }
    }
    if ($in_use) {
      $usage_array = array(
        '#theme' => 'table',
        '#header' => array(
          t('Module Key'),
          t('Mail System'),
        ),
        '#rows' => $usage_rows,
      );
      $form['sparkpost_status'] = array(
        '#type' => 'markup',
        '#markup' => t('Sparkpost is currently configured to be used by the following Module Keys. To change these settings or configure additional systems to use Sparkpost, use !link.<br /><br />!table', array(
          '!link' => l(t('Mail System'), 'admin/config/system/mailsystem'),
          '!table' => drupal_render($usage_array),
        )),
      );
    }
    elseif (!$form_state['rebuild']) {
      drupal_set_message(t('PLEASE NOTE: Sparkpost is not currently configured for use by Drupal. In order to route your email through Sparkpost, you must configure at least one MailSystemInterface (other than sparkpost) to use "SparkpostMailSystem" in !link, or you will only be able to send Test Emails through Sparkpost.', array(
        '!link' => l(t('Mail System'), 'admin/config/system/mailsystem'),
      )), 'warning');
    }
    $form['email_options'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#title' => t('Email options'),
    );
    $form['email_options']['sparkpost_debug'] = array(
      '#type' => 'checkbox',
      '#title' => t('Debug'),
      '#description' => t('If selected, exceptions will be sent over to watchdog.'),
      '#default_value' => variable_get('sparkpost_debug', TRUE),
    );
    $from = sparkpost_from();
    $form['email_options']['sparkpost_from'] = array(
      '#title' => t('From address'),
      '#type' => 'textfield',
      '#description' => t('The sender email address. If this address has not been verified, messages will not be sent. This address will appear in the "from" field, and any emails sent through Sparkpost with a "from" address will have that address moved to the Reply-To field.'),
      '#default_value' => $from['email'],
    );
    $form['email_options']['sparkpost_from_name'] = array(
      '#type' => 'textfield',
      '#title' => t('From name'),
      '#default_value' => $from['name'],
      '#description' => t('Optionally enter a from name to be used.'),
    );
    $formats = filter_formats();
    $options = array(
      '' => t('-- Select --'),
    );
    foreach ($formats as $v => $format) {
      $options[$v] = $format->name;
    }
    $form['email_options']['sparkpost_filter_format'] = array(
      '#type' => 'select',
      '#title' => t('Input format'),
      '#description' => t('If selected, the input format to apply to the message body before sending to the Sparkpost API.'),
      '#options' => $options,
      '#default_value' => array(
        variable_get('sparkpost_filter_format', 'full_html'),
      ),
    );
    $form['email_options']['sparkpost_send_async'] = array(
      '#type' => 'checkbox',
      '#title' => t('Send asynchronous'),
      '#default_value' => variable_get('sparkpost_send_async', FALSE),
      '#description' => t('If selected, the mails will not be sent right away, but queued and possibly sent with cron or drush.'),
    );
    $form['email_options']['sparkpost_skip_cron'] = array(
      '#type' => 'checkbox',
      '#title' => t('Skip queue on cron'),
      '#default_value' => variable_get('sparkpost_skip_cron', FALSE),
      '#description' => t('If selected, the mail queue will not be processed by cron runs. Use this only if you manually run the queue with drush (for example).'),
      '#states' => array(
        'visible' => array(
          ':input[name="sparkpost_send_async"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['email_options']['sparkpost_timeout'] = array(
      '#type' => 'textfield',
      '#title' => t('Timeout'),
      '#default_value' => variable_get('sparkpost_timeout', 10),
      '#element_validate' => array(
        'element_validate_integer_positive',
      ),
      '#description' => t('Set custom timeout (in seconds).'),
    );
  }
  return system_settings_form($form);
}