You are here

function mailsystem_admin_settings in Mail System 7.3

Same name and namespace in other branches
  1. 8 mailsystem.admin.inc \mailsystem_admin_settings()
  2. 8.2 mailsystem.admin.inc \mailsystem_admin_settings()
  3. 6.2 mailsystem.admin.inc \mailsystem_admin_settings()
  4. 6 mailsystem.admin.inc \mailsystem_admin_settings()
  5. 7 mailsystem.admin.inc \mailsystem_admin_settings()
  6. 7.2 mailsystem.admin.inc \mailsystem_admin_settings()

Form constructor for the mailsystem settings form.

1 string reference to 'mailsystem_admin_settings'
mailsystem_menu in ./mailsystem.module
Implements hook_menu().

File

./mailsystem.admin.inc, line 11
Administrative interface for the mail_system variable.

Code

function mailsystem_admin_settings() {
  $args = array(
    '!interface' => url('http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7'),
    '@interface' => 'MailSystemInterface',
    '!format' => url('http://api.drupal.org/api/drupal/includes--mail.inc/function/MailSystemInterface%3A%3Aformat/7'),
    '@format' => 'format()',
    '!mail' => url('http://api.drupal.org/api/drupal/includes--mail.inc/function/MailSystemInterface%3A%3Amail/7'),
    '!hook_mail' => 'http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_mail/7',
    '@mail' => 'mail()',
    '!default_class' => url('http://api.drupal.org/api/drupal/modules--system--system.mail.inc/class/DefaultMailSystem/7'),
    '@default_class' => mailsystem_default_value(),
    '%module' => 'module',
    '%key' => 'key',
  );
  $mail_system = mailsystem_read_settings();
  $delivery_classes = mailsystem_admin_get_delivery_classes();
  $formatter_classes = mailsystem_admin_get_formatter_classes();
  $mail_modules = mailsystem_admin_get_mail_modules();
  $form['mailsystem'] = array(
    '#type' => 'fieldset',
    '#title' => t('Mail System Settings'),
    '#description' => t('Drupal provides a default <a href="!interface"><code>@interface</code></a> class called <a href="!default_class"><code>@default_class</code></a>. Modules may provide additional classes. Each <a href="!interface"><code>@interface</code></a> class may be associated with one or more identifiers, composed of a %module and an optional %key. Each email being sent also has a %module and a %key. To decide which class to use, Drupal uses the following search order: <ol><li>The class associated with the %module and %key, if any.</li><li>The class associated with the %module, if any.</li><li>The site-wide default <a href="!interface"><code>@interface</code></a> class.</li></ol>', $args),
    '#collapsible' => FALSE,
    '#tree' => TRUE,
  );

  // Generate a list of themes which may used to render emails.
  $theme_options = array(
    'current' => t('Current'),
    'default' => t('Default'),
  );
  if (module_exists('domain_theme')) {
    $theme_options['domain'] = t('Domain Theme');
  }

  // Get a list of all themes.
  $themes = list_themes();
  foreach ($themes as $name => $theme) {
    if ($theme->status == 1) {
      $theme_options[$name] = $theme->info['name'];
    }
  }
  $form['mailsystem']['mailsystem_theme'] = array(
    '#type' => 'select',
    '#title' => t('Theme to render the emails'),
    '#description' => t('Select the theme that will be used to render the emails. This can be either the current theme, the default theme, the domain theme or any active theme.'),
    '#options' => $theme_options,
    '#default_value' => variable_get('mailsystem_theme', 'current'),
  );
  $form['mailsystem'][mailsystem_default_id()] = array(
    '#type' => 'fieldset',
    '#title' => t('Site-wide default mail system'),
  );
  $form['mailsystem'][mailsystem_default_id()]['mail'] = array(
    '#type' => 'select',
    '#title' => t('Delivery'),
    '#options' => $delivery_classes,
    '#default_value' => $mail_system[mailsystem_default_id()]['mail'],
    '#description' => t('Class used to send the mail'),
  );
  $form['mailsystem'][mailsystem_default_id()]['format'] = array(
    '#type' => 'select',
    '#title' => t('Formatting'),
    '#options' => $formatter_classes,
    '#default_value' => $mail_system[mailsystem_default_id()]['format'],
    '#description' => t('Class used to format the body of the mail'),
  );
  unset($mail_system[mailsystem_default_id()]);
  foreach ($mail_system as $id => $settings) {
    $form['mailsystem'][$id] = array(
      '#type' => 'fieldset',
      '#title' => t('Custom settings for mail-id %id', array(
        '%id' => $id,
      )),
    );
    $form['mailsystem'][$id]['mail'] = array(
      '#type' => 'select',
      '#title' => t('Delivery'),
      '#options' => $delivery_classes,
      '#default_value' => $settings['mail'],
      '#description' => t('Class used to send the mail'),
    );
    $form['mailsystem'][$id]['format'] = array(
      '#type' => 'select',
      '#title' => t('Formatting'),
      '#options' => $formatter_classes,
      '#default_value' => $settings['format'],
      '#description' => t('Class used to format the body of the mail'),
    );
    $form['mailsystem'][$id]['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Remove custom settings for mail-id @id', array(
        '@id' => $id,
      )),
      '#submit' => array(
        'mailsystem_admin_remove_setting_submit',
      ),
      '#limit_validation_errors' => array(
        array(
          'mailsystem',
          $id,
        ),
      ),
    );
  }
  $form['mailsystem']['add-custom-settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add custom settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#element_validate' => array(
      'mailsystem_admin_add_setting_validate',
    ),
  );
  $form['mailsystem']['add-custom-settings']['module'] = array(
    '#type' => 'select',
    '#title' => t('Module'),
    '#options' => $mail_modules,
  );
  $form['mailsystem']['add-custom-settings']['key'] = array(
    '#type' => 'textfield',
    '#title' => t('Key'),
    '#size' => 30,
    '#description' => t('An optional key which further specifies the mail in question. You may have to examine the source code of the <a href="!hook_mail">hook_mail</a> implementation of the module in question in order to find an appropriate value', $args),
  );
  $form['mailsystem']['add-custom-settings']['mail'] = array(
    '#type' => 'select',
    '#title' => t('Delivery'),
    '#options' => $delivery_classes,
    '#description' => t('Class used to send the mail'),
  );
  $form['mailsystem']['add-custom-settings']['format'] = array(
    '#type' => 'select',
    '#title' => t('Formatting'),
    '#options' => $formatter_classes,
    '#description' => t('Class used to format the body of the mail'),
  );
  $form['mailsystem']['add-custom-settings']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add custom settings'),
    '#submit' => array(
      'mailsystem_admin_add_setting_submit',
    ),
    '#limit_validation_errors' => array(
      array(
        'mailsystem',
        'add-custom-settings',
      ),
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save settings'),
  );
  return $form;
}