You are here

public function IpLoginSettingsForm::submitForm in IP Login 4.x

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/IpLoginSettingsForm.php, line 98

Class

IpLoginSettingsForm
Configure ip_login settings.

Namespace

Drupal\ip_login\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $config = $this
    ->config('ip_login.settings');
  $form_state
    ->cleanValues();
  $auto_login = $form_state
    ->getValue('auto_login');
  $form_login = $form_state
    ->getValue('form_login');
  $old_auto_login = $config
    ->get('auto_login');
  $config
    ->set('auto_login', $auto_login);
  $old_form_login = $config
    ->get('form_login');
  $config
    ->set('form_login', $form_login);

  // If the login mode is changed, we need to clear the render cache so the
  // auto-login can be attempted on subsequent page loads, if configured.
  if ($auto_login != $old_auto_login || $form_login != $old_form_login) {
    $this->cacheFactory
      ->get('render')
      ->deleteAll();
    $this->cacheTagsInvalidator
      ->invalidateTags([
      'ip_login',
    ]);

    // We need to invalidate the container so the middleware services are
    // registered based on the settings above.
    // @see \Drupal\ip_login\IpLoginServiceProvider::register()
    \Drupal::service('kernel')
      ->invalidateContainer();
  }
  $config
    ->save();
}