You are here

function mailsystem_admin_settings in Mail System 7

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.3 mailsystem.admin.inc \mailsystem_admin_settings()
  6. 7.2 mailsystem.admin.inc \mailsystem_admin_settings()

@file Administrative form for setting the mail_system variable.

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

File

./mailsystem.admin.inc, line 7
Administrative form for setting the mail_system variable.

Code

function mailsystem_admin_settings() {
  $form = array(
    '#submit' => array(
      'mailsystem_admin_settings_submit',
    ),
  );
  $mail_system = mailsystem_get();
  $mail_defaults = mailsystem_defaults();
  $mailsystem_classes = mailsystem_get_classes($mail_system);
  $descriptions = array();
  foreach (system_rebuild_module_data() as $item) {
    if ($item->status) {
      $descriptions[$item->name] = (empty($item->info['package']) ? '' : $item->info['package']) . ' » ' . t('!module module', array(
        '!module' => $item->info['name'],
      ));
    }
  }
  asort($descriptions);
  $form['mailsystem'] = array(
    '#type' => 'fieldset',
    '#title' => t('Mail System Settings'),
    '#description' => t('Drupal provides a default mail system called %def_class. Modules may provide additional mail systems. Each mail system is 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 mail system to use, drupal uses the following search order: <ol><li>The mail system associated with the %module and %key, if any.</li><li>The mail system associated with the %module, if any.</li><li>The site-wide default mail system.</li></ol>', array(
      '%def_class' => mailsystem_default_value(),
      '%module' => 'module',
      '%key' => 'key',
    )),
    '#collapsible' => FALSE,
    '#tree' => TRUE,
  );
  $form['mailsystem'][mailsystem_default_id()] = array(
    '#type' => 'select',
    '#title' => t('Site-wide default mail system'),
    '#options' => $mailsystem_classes,
    '#default_value' => $mail_system[mailsystem_default_id()],
  );
  $mailsystem_classes = array(
    mailsystem_default_id() => t('Remove this setting.'),
  ) + $mailsystem_classes;
  foreach (array_diff_key($mail_system, $mail_defaults) as $id => $class) {

    // Separate $id into $module and $key.
    $module = $id;
    while ($module && empty($descriptions[$module])) {

      // Remove a key from the end
      $module = implode('_', explode('_', $module, -1));
    }

    // Set $title to the human-readable module name.
    list($title) = array_slice(explode(' » ', $descriptions[$module]), -1, 1);
    if ($key = substr($id, strlen($module) + 1)) {
      $title .= " ({$key} key)";
    }
    $form['mailsystem'][$id] = array(
      '#type' => 'select',
      '#title' => $title,
      '#options' => $mailsystem_classes,
      '#default_value' => $class,
    );
    unset($descriptions[$module]);
  }
  $form['identifier'] = array(
    '#type' => 'fieldset',
    '#title' => t('New Setting'),
    '#description' => t('Add a new %module and %key to the settings list.', array(
      '%module' => 'module',
      '%key' => 'key',
    )),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  array_unshift($descriptions, t('-- Select --'));
  $form['identifier']['module'] = array(
    '#type' => 'select',
    '#title' => t('Module'),
    '#options' => $descriptions,
  );
  $form['identifier']['key'] = array(
    '#type' => 'textfield',
    '#title' => t('Key'),
    '#size' => 80,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save settings'),
  );
  return $form;
}