You are here

public function SettingsForm::submitForm in Two-factor Authentication (TFA) 8

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 406

Class

SettingsForm
The admin configuration page.

Namespace

Drupal\tfa\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $validation_plugin = $form_state
    ->getValue('tfa_validate');
  $allowed_validation_plugins = $form_state
    ->getValue('tfa_allowed_validation_plugins');

  // Default validation plugin must always be allowed.
  $allowed_validation_plugins[$validation_plugin] = $validation_plugin;
  $validation_plugin_settings = $form_state
    ->getValue('validation_plugin_settings');
  if (empty($validation_plugin_settings)) {
    $validation_plugin_settings = [];
  }

  // Delete tfa data if plugin is disabled.
  if ($this
    ->config('tfa.settings')
    ->get('enabled') && !$form_state
    ->getValue('tfa_enabled')) {
    $this->userData
      ->delete('tfa');
  }
  $send_plugins = $form_state
    ->getValue('tfa_send') ?: [];
  $login_plugins = $form_state
    ->getValue('tfa_login') ?: [];
  $this
    ->config('tfa.settings')
    ->set('enabled', $form_state
    ->getValue('tfa_enabled'))
    ->set('required_roles', $form_state
    ->getValue('tfa_required_roles'))
    ->set('send_plugins', array_filter($send_plugins))
    ->set('login_plugins', array_filter($login_plugins))
    ->set('allowed_validation_plugins', array_filter($allowed_validation_plugins))
    ->set('default_validation_plugin', $validation_plugin)
    ->set('validation_plugin_settings', $validation_plugin_settings)
    ->set('validation_skip', $form_state
    ->getValue('validation_skip'))
    ->set('encryption', $form_state
    ->getValue('encryption_profile'))
    ->set('tfa_flood_uid_only', $form_state
    ->getValue('tfa_flood_uid_only'))
    ->set('tfa_flood_window', $form_state
    ->getValue('tfa_flood_window'))
    ->set('tfa_flood_threshold', $form_state
    ->getValue('tfa_flood_threshold'))
    ->set('mail.tfa_enabled_configuration.subject', $form_state
    ->getValue('tfa_enabled_configuration_subject'))
    ->set('mail.tfa_enabled_configuration.body', $form_state
    ->getValue('tfa_enabled_configuration_body'))
    ->set('mail.tfa_disabled_configuration.subject', $form_state
    ->getValue('tfa_disabled_configuration_subject'))
    ->set('mail.tfa_disabled_configuration.body', $form_state
    ->getValue('tfa_disabled_configuration_body'))
    ->set('help_text', $form_state
    ->getValue('help_text'))
    ->save();
  parent::submitForm($form, $form_state);
}