You are here

public function LazyForm::validateForm in Lazy-load 8.3

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/LazyForm.php, line 554

Class

LazyForm
Configure Lazy settings for this site.

Namespace

Drupal\lazy\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  if (($custom_media = $form_state
    ->getValue('lazysizes_customMedia')) && !$this
    ->isJson($custom_media)) {
    $form_state
      ->setErrorByName('lazysizes_customMedia', $this
      ->t('Not a valid JavaScript object.'));
  }
  $library_path = $form_state
    ->getValue('libraryPath');
  if (substr_compare($library_path, '/', 0, 1, TRUE) !== 0 && substr_compare($library_path, 'https://', 0, 8, TRUE) !== 0) {
    $form_state
      ->setErrorByName('libraryPath', $this
      ->t('The path must either start with <code>/</code> or <code>https://</code>'));
  }
  if (substr_compare($library_path, '/', -1, 1, TRUE) === 0) {
    $form_state
      ->setErrorByName('libraryPath', $this
      ->t('The path must not have a trailing forward slash.'));
  }
}