You are here

public function SettingsForm::validateForm in Session Limit 2.x

Same name and namespace in other branches
  1. 8 src/Form/SettingsForm.php \Drupal\session_limit\Form\SettingsForm::validateForm()

Form validation 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 FormBase::validateForm

File

src/Form/SettingsForm.php, line 145

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\session_limit\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $maxSessions = $form_state
    ->getValue([
    'session_limit_max',
  ]);
  if (!is_numeric($maxSessions)) {
    $form_state
      ->setErrorByName('session_limit_max', $this
      ->t('You must enter a number for the maximum number of active sessions'));
  }
  elseif ($maxSessions < 0) {
    $form_state
      ->setErrorByName('session_limit_max', $this
      ->t('Maximum number of active sessions must be positive'));
  }
}