You are here

public function SecureLoginConfigForm::validateForm in Secure Login 8

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/SecureLoginConfigForm.php, line 175

Class

SecureLoginConfigForm
Implements a SecureLogin Config form.

Namespace

Drupal\securelogin\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if (!$form_state
    ->getValue('base_url')) {
    $form_state
      ->setValue('base_url', NULL);
  }
  elseif (!UrlHelper::isValid($form_state
    ->getValue('base_url'), TRUE)) {
    $form_state
      ->setErrorByName('base_url', $this
      ->t('The secure base URL must be a valid URL.'));
  }
  elseif (strtolower(parse_url($form_state
    ->getValue('base_url'), PHP_URL_SCHEME)) !== 'https') {
    $form_state
      ->setErrorByName('base_url', $this
      ->t('The secure base URL must start with <em>https://</em>.'));
  }
  parent::validateForm($form, $form_state);
}