You are here

public function SettingsForm::validateForm in External Link Pop-up 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 86

Class

SettingsForm
Implements the external_link_popup.settings route.

Namespace

Drupal\external_link_popup\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $whitelist = trim($form_state
    ->getValue('whitelist'));
  if ($whitelist && !preg_match('/^([^\\s\\/\\,+]+[^\\S\\n]*\\n)*([^\\s\\/\\,+]+)$/', $whitelist)) {
    $form_state
      ->setErrorByName('whitelist', $this
      ->t('Please match the requested format.'));
  }
  else {
    $form_state
      ->setValue('whitelist', $whitelist);
  }
  if ($form_state
    ->getValue([
    'width',
    'value',
  ]) && $form_state
    ->getValue([
    'width',
    'units',
  ]) === '%' && $form_state
    ->getValue([
    'width',
    'value',
  ]) > 100) {
    $form_state
      ->setErrorByName('width][value', $this
      ->t('%name must be higher than or equal to %min.', [
      '%name' => $form['width']['#title'],
      '%min' => 100,
    ]));
  }
}