You are here

function subscriptions_mail_form_alter in Subscriptions 5.2

Implementation of hook_form_alter().

Adds to the General Settings part at admin/settings/subscriptions and possibly a warning and [Remove legacy template] button at admin/build/mail_edit/subscriptions-....

File

./subscriptions_mail.module, line 253
Subscriptions module mail gateway.

Code

function subscriptions_mail_form_alter($form_id, &$form) {
  global $user;
  $tr = 't';
  if ($form_id == 'subscriptions_settings_form') {

    // check the $base_url (#199039, #226335)
    $url = url("", NULL, NULL, TRUE);
    if (empty($_POST) && preg_match('!//($|/|localhost/|([0-9]{1,3}\\.){3}[0-9]{1,3}/)!', $url)) {
      drupal_set_message(t('Your installation returns %url as the base URL of the site. This is probably not what you want, and it can usually be fixed by setting the %variable variable in your %file file.', array(
        '%url' => $url,
        '%variable' => '$base_url',
        '%file' => 'settings.php',
      )), 'error');
    }
    $form['mail_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Mail settings'),
      '#weight' => -3,
    );
    $form['mail_settings']['subscriptions_site_mail'] = array(
      '#type' => 'textfield',
      '#title' => t('E-mail address'),
      '#default_value' => _subscriptions_mail_site_mail(TRUE),
      '#description' => t('A valid e-mail address to be used as the "From" address by the auto-mailer for !module notifications.  To lessen the likelihood of e-mail being marked as spam, this e-mail address should use the same domain as the website.', array(
        '!module' => 'Subscriptions',
      )) . '<br />' . t('Clear this field to use the default site e-mail address.'),
    );
    $form['mail_settings']['subscriptions_site_mail_name'] = array(
      '#type' => 'textfield',
      '#title' => t('E-mail name'),
      '#default_value' => variable_get('subscriptions_site_mail_name', ''),
      '#description' => t('An optional name to go with the e-mail address above, no "double-quotes".') . '<br />' . t('Clear this field to use the e-mail address only &mdash; some e-mail clients will display only the portion of the address to the left of the @ sign.'),
    );
    $form['mail_settings']['subscriptions_number_of_mails'] = array(
      '#type' => 'textfield',
      '#title' => t('Maximum number of notifications to send per cron job'),
      '#default_value' => variable_get('subscriptions_number_of_mails', 0),
      '#description' => t("!module tries to use a good part of the remaining time during each cron run. If it's using too much time or you need to limit the number of outgoing e-mails for some other reason, then set the number here. The default is 0, which means unlimited.", array(
        '!module' => 'Subscriptions',
      )),
    );
    $form['mail_settings']['subscriptions_watchgood'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display watchdog entries for successful mailings'),
      '#default_value' => variable_get('subscriptions_watchgood', 1),
      '#description' => t('Logs successful mailings to the watchdog log.  Default is ON, but with many subscribers this will generate a huge number of log entries.'),
    );
    $form['mail_settings']['subscriptions_watchstats'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display summary watchdog entries per cron job'),
      '#default_value' => variable_get('subscriptions_watchstats', 1),
      '#description' => t('Logs the mailing counts, time spent, and size of the remaining queue to the watchdog log.  This is valuable information for estimating the load on the cron job and on your mail server.  Default is ON.'),
    );
  }
  elseif ($form_id == 'mail_edit_form' && substr($form['mailkey']['#value'], 0, 14) == 'subscriptions-') {
    if ($form['mailkey']['#value'] != SUBSCRIPTIONS_DIGEST_MAILKEY && (variable_get('subscriptions_email_body', '') || variable_get('subscriptions_email_subject', ''))) {
      $form['legacy'] = array(
        '#type' => 'fieldset',
        '#title' => t('Legacy template'),
        '#attributes' => array(
          'class' => 'error',
        ),
        '#weight' => -101,
      );
      $form['legacy']['explain'] = array(
        '#type' => 'item',
        '#value' => t('You have Subscriptions 5.x-1.x-dev template variables defined in your database.<br />As long as these are in place, the template values below will be ignored!'),
      );
      $form['legacy']['remove_legacy'] = array(
        '#type' => 'submit',
        '#value' => t('Remove legacy template'),
      );
      $form['#submit'] = array_reverse($form['#submit']);

      // we want to go first!
      $form['#submit']['subscriptions_mail_mail_edit_form_submit'] = array();
      $form['#submit'] = array_reverse($form['#submit']);
    }
    foreach (array(
      '!sender_name',
      '!sender_page',
    ) as $key) {
      $expl = $form['help']['#variables'][$key];
      if ($expl[strlen($expl) - 1] == '.') {
        $add_dot = TRUE;
        $expl = substr($expl, 0, strlen($expl) - 1);
      }
      $expl .= ' ' . t('(if the sender is visible)') . (!empty($add_dot) ? '.' : '');
      $form['help']['#variables'][$key] = $expl;
    }
  }
}