function SiteInformationForm::validateForm

Same name and namespace in other branches
  1. 10 core/modules/system/src/Form/SiteInformationForm.php \Drupal\system\Form\SiteInformationForm::validateForm()
  2. 9 core/modules/system/src/Form/SiteInformationForm.php \Drupal\system\Form\SiteInformationForm::validateForm()
  3. 8.9.x core/modules/system/src/Form/SiteInformationForm.php \Drupal\system\Form\SiteInformationForm::validateForm()
  4. main core/modules/system/src/Form/SiteInformationForm.php \Drupal\system\Form\SiteInformationForm::validateForm()

Overrides ConfigFormBase::validateForm

File

core/modules/system/src/Form/SiteInformationForm.php, line 147

Class

SiteInformationForm
Configure site information settings for this site.

Namespace

Drupal\system\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  // Validate front page path.
  if (($value = $form_state->getValue('site_frontpage')) && $value[0] !== '/') {
    $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' has to start with a slash.", [
      '%path' => $form_state->getValue('site_frontpage'),
    ]));
  }
  if (!$this->pathValidator
    ->isValid($form_state->getValue('site_frontpage'))) {
    $form_state->setErrorByName('site_frontpage', $this->t("Either the path '%path' is invalid or you do not have access to it.", [
      '%path' => $form_state->getValue('site_frontpage'),
    ]));
  }
  // Get the normal paths of both error pages.
  if (($value = $form_state->getValue('site_403')) && $value[0] !== '/') {
    $form_state->setErrorByName('site_403', $this->t("The path '%path' has to start with a slash.", [
      '%path' => $form_state->getValue('site_403'),
    ]));
  }
  if (($value = $form_state->getValue('site_404')) && $value[0] !== '/') {
    $form_state->setErrorByName('site_404', $this->t("The path '%path' has to start with a slash.", [
      '%path' => $form_state->getValue('site_404'),
    ]));
  }
  // Validate 403 error path.
  if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator
    ->isValid($form_state->getValue('site_403'))) {
    $form_state->setErrorByName('site_403', $this->t("Either the path '%path' is invalid or you do not have access to it.", [
      '%path' => $form_state->getValue('site_403'),
    ]));
  }
  // Validate 404 error path.
  if (!$form_state->isValueEmpty('site_404') && !$this->pathValidator
    ->isValid($form_state->getValue('site_404'))) {
    $form_state->setErrorByName('site_404', $this->t("Either the path '%path' is invalid or you do not have access to it.", [
      '%path' => $form_state->getValue('site_404'),
    ]));
  }
  parent::validateForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.