You are here

public function LoginDisableSettingsForm::submitForm in Login Disable 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/LoginDisableSettingsForm.php \Drupal\login_disable\Form\LoginDisableSettingsForm::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/LoginDisableSettingsForm.php, line 83

Class

LoginDisableSettingsForm
Class LoginDisableSettingsForm.

Namespace

Drupal\login_disable\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('login_disable.settings');
  foreach (Element::children($form) as $variable) {
    $config
      ->set($variable, $form_state
      ->getValue($form[$variable]['#parents']));
  }
  $config
    ->save();
  if (method_exists($this, '_submitForm')) {
    $this
      ->_submitForm($form, $form_state);
  }

  // If user is prevented from login and force logout is selected then logout
  // all users.
  if ($form_state
    ->getValue('login_disable_is_active', FALSE) && $form_state
    ->getValue('login_disable_force_logout', FALSE)) {

    // Ignore super admin and current user from session kill.
    $ignore_uids = array_unique([
      1,
      \Drupal::currentUser()
        ->id(),
    ]);
    \Drupal::database()
      ->delete('sessions')
      ->condition('uid', $ignore_uids, 'NOT IN')
      ->execute();
  }
  parent::submitForm($form, $form_state);
}