public function SessionLimitForm::submitForm in Session Limit 8
Same name and namespace in other branches
- 2.x src/Form/SessionLimitForm.php \Drupal\session_limit\Form\SessionLimitForm::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 FormInterface::submitForm
File
- src/Form/ SessionLimitForm.php, line 70 
Class
Namespace
Drupal\session_limit\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
  /** @var SessionManager $session_manager */
  $session_manager = \Drupal::service('session_manager');
  $current_session_id = Crypt::hashBase64($session_manager
    ->getId());
  /** @var SessionLimit $session_limit */
  $session_limit = \Drupal::service('session_limit');
  $session_reference = $form_state
    ->getValue([
    'session_reference',
  ]);
  $sid = $form['active_sessions']['#value'][$session_reference]->sid;
  if ($current_session_id == $sid) {
    // @todo the user is not seeing the message below.
    $session_limit
      ->sessionActiveDisconnect($this
      ->t('You chose to end this session.'));
    $form_state
      ->setRedirect('user.login');
  }
  else {
    $session_limit
      ->sessionDisconnect($sid, $this
      ->t('Your session was deliberately ended from another session.'));
    $form_state
      ->setRedirect('<front>');
  }
}