You are here

public function SettingsForm::submitForm in PHPMailer SMTP 2.1.x

Same name and namespace in other branches
  1. 8 src/Form/SettingsForm.php \Drupal\phpmailer_smtp\Form\SettingsForm::submitForm()
  2. 2.x src/Form/SettingsForm.php \Drupal\phpmailer_smtp\Form\SettingsForm::submitForm()
  3. 2.0.x src/Form/SettingsForm.php \Drupal\phpmailer_smtp\Form\SettingsForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/SettingsForm.php, line 349

Class

SettingsForm
Defines a form to configure PHPMailer SMTP settings.

Namespace

Drupal\phpmailer_smtp\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();

  // Save the configuration changes.
  $phpmailer_smtp_config = $this
    ->config('phpmailer_smtp.settings');
  $phpmailer_smtp_config
    ->set('smtp_host', $values['smtp_host'])
    ->set('smtp_hostbackup', $values['smtp_hostbackup'])
    ->set('smtp_port', $values['smtp_port'])
    ->set('smtp_protocol', $values['smtp_protocol'])
    ->set('smtp_ssl_verify_peer', $values['smtp_ssl_verify_peer'])
    ->set('smtp_ssl_verify_peer_name', $values['smtp_ssl_verify_peer_name'])
    ->set('smtp_ssl_allow_self_signed', $values['smtp_ssl_allow_self_signed'])
    ->set('smtp_username', $values['smtp_username'])
    ->set('smtp_authentication_type', $values['smtp_authentication_type'])
    ->set('smtp_fromname', $values['smtp_fromname'])
    ->set('smtp_ehlo_host', $values['smtp_ehlo_host'])
    ->set('smtp_always_replyto', $values['smtp_always_replyto'])
    ->set('smtp_keepalive', $values['smtp_keepalive'])
    ->set('smtp_debug', $values['smtp_debug'])
    ->set('smtp_debug_log', $values['smtp_debug_log'])
    ->set('smtp_timeout', $values['smtp_timeout'])
    ->set('smtp_envelope_sender_option', $values['smtp_envelope_sender_option'])
    ->set('smtp_envelope_sender', $values['smtp_envelope_sender']);

  // Only save option if it is present.
  if (!empty($values['smtp_hide_password'])) {
    $phpmailer_smtp_config
      ->set('smtp_hide_password', $values['smtp_hide_password']);
  }

  // Only save the password if it is not empty.
  if (!empty($values['smtp_password'])) {
    $phpmailer_smtp_config
      ->set('smtp_password', $values['smtp_password']);
  }

  // Check option to delete the password.
  if (!empty($values['smtp_delete_password'])) {
    $phpmailer_smtp_config
      ->set('smtp_password', '');
  }
  $phpmailer_smtp_config
    ->save();

  // Send a test email message, if an email address was entered.
  if ($values['phpmailer_smtp_test']) {
    $this
      ->sendTestEmail($values);
  }
  parent::submitForm($form, $form_state);
}