You are here

public function SettingsForm::validateForm in Critical CSS 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/SettingsForm.php, line 91

Class

SettingsForm
Configuration form for critical css.

Namespace

Drupal\critical_css\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $criticalCssDirPath = $form_state
    ->getValue('critical_css_dir_path');
  if (substr($criticalCssDirPath, 0, 1) != '/') {
    $form_state
      ->setErrorByName('critical_css_dir_path', $this
      ->t('Critical CSS base directory must start with a leading slash.'));
  }
  if (strstr($criticalCssDirPath, '..')) {
    $form_state
      ->setErrorByName('critical_css_dir_path', $this
      ->t('Critical CSS base directory must not contain "..".'));
  }
}