You are here

public function PageSpecificClassSettingsForm::validateForm in Page Specific Class 8

Same name and namespace in other branches
  1. 2.0.x src/Form/PageSpecificClassSettingsForm.php \Drupal\page_specific_class\Form\PageSpecificClassSettingsForm::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/PageSpecificClassSettingsForm.php, line 57

Class

PageSpecificClassSettingsForm
Configure custom settings for Page Specific Class.

Namespace

Drupal\page_specific_class\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $enteredArr = explode(PHP_EOL, $form_state
    ->getValue('url_with_class'));
  foreach ($enteredArr as $values) {
    $urlWithClassArr = explode("|", $values);
    $url = $urlWithClassArr[0];
    if ($url[0] !== '/') {
      $form_state
        ->setErrorByName('url_with_class', $this
        ->t("@url path needs to start with a slash.", [
        '@url' => $url,
      ]));
    }
  }
}