You are here

function _disable_smtp in SMTP Authentication Support 8

Helper function to disable SMTP and restore the default mailsystem.

4 calls to _disable_smtp()
smtp_modules_installed in ./smtp.install
Disable the SMTP mailsystem if the mailsystem module is installed.
smtp_requirements in ./smtp.install
Implements hook_requirements().
smtp_uninstall in ./smtp.install
Implements hook_uninstall().
smtp_update_8004 in ./smtp.install
If mailsystem exists, disable smtp mailsystem automatically.

File

./smtp.install, line 139
The installation instructions for the SMTP Authentication Support.

Code

function _disable_smtp() {
  $config = \Drupal::service('config.factory');

  // Always make sure SMTP is disabled.
  $smtp_config = $config
    ->getEditable('smtp.settings');
  if (!$smtp_config
    ->get('smtp_on')) {
    return;
  }

  // Set the internal SMTP module config off.
  $smtp_config
    ->set('smtp_on', FALSE)
    ->save();

  // Set the default back to either the previous mail system or php_mail.
  $mail_config = $config
    ->getEditable('system.mail');
  $current_default = $mail_config
    ->get('interface.default');
  $system_default = 'php_mail';
  if ($current_default == 'SMTPMailSystem') {
    $default_interface = !$smtp_config
      ->get('prev_mail_system') ? $smtp_config
      ->get('prev_mail_system') : $system_default;
    $mail_config
      ->set('interface.default', $default_interface)
      ->save();
  }
}