You are here

public function SocialAuthSettingsForm::validateForm in Social Auth 8

Same name and namespace in other branches
  1. 8.2 src/Form/SocialAuthSettingsForm.php \Drupal\social_auth\Form\SocialAuthSettingsForm::validateForm()
  2. 3.x src/Form/SocialAuthSettingsForm.php \Drupal\social_auth\Form\SocialAuthSettingsForm::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/SocialAuthSettingsForm.php, line 134

Class

SocialAuthSettingsForm
Defines a form that configures Social Auth settings.

Namespace

Drupal\social_auth\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $post_login = $values['post_login'];
  $routes = $this->routeProvider
    ->getRoutesByNames(array(
    $post_login,
  ));
  if (empty($routes)) {

    // If it is not a route and value does not start with '/', '#', or '?'.
    if (!in_array($post_login[0], array(
      "/",
      "#",
      "?",
    ))) {
      $form_state
        ->setErrorByName('post_login', $this
        ->t("The route doesn't exist. If path, it must begin with <em>/, #</em> or <em>?</em>"));
    }

    // If path is valid, check if it exists.
    if (!$this->pathValidator
      ->getUrlIfValidWithoutAccessCheck($post_login)) {
      $form_state
        ->setErrorByName('post_login', $this
        ->t("The path or route you entered is not valid."));
    }
  }
}