You are here

public function RedirectLogoutSettings::validateForm in Redirect after logout 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/RedirectLogoutSettings.php, line 120

Class

RedirectLogoutSettings
Class RedirectLogoutSettings.

Namespace

Drupal\redirect_after_logout\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  // Validate redirect destination.
  $value = $form_state
    ->getValue('redirect_after_logout_destination');
  if (UrlHelper::isExternal($value)) {
    return;
  }
  if (($value = $form_state
    ->getValue('redirect_after_logout_destination')) && $value[0] !== '/' && $value !== '<front>') {
    $form_state
      ->setErrorByName('redirect_after_logout_destination', $this
      ->t("The path '%path' has to start with a slash.", [
      '%path' => $form_state
        ->getValue('redirect_after_logout_destination'),
    ]));
  }
  if (!$this->pathValidator
    ->isValid($form_state
    ->getValue('redirect_after_logout_destination'))) {
    $form_state
      ->setErrorByName('redirect_after_logout_destination', $this
      ->t("Either the path '%path' is invalid or you do not have access to it.", [
      '%path' => $form_state
        ->getValue('redirect_after_logout_destination'),
    ]));
  }
  parent::validateForm($form, $form_state);
}