You are here

public function SuggestionAdminForm::validateForm in Autocomplete Search Suggestions 3.0.x

Same name and namespace in other branches
  1. 8 src/Form/SuggestionAdminForm.php \Drupal\suggestion\Form\SuggestionAdminForm::validateForm()

Validation function for the suggestion edit form.

Parameters

array $form: A drupal form array.

\Drupal\Core\Form\FormStateInterface $form_state: A Drupal FormStateInterface object.

Overrides FormBase::validateForm

File

src/Form/SuggestionAdminForm.php, line 207

Class

SuggestionAdminForm
Suggestion configuration form.

Namespace

Drupal\suggestion\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('entry_style') == 'simple') {
    if (!preg_match('/^[a-z_0-9]+$/', trim($form_state
      ->getValue('field_name')))) {
      $form_state
        ->setErrorByName('field_name', $this
        ->t('Illegal character(s) in field name.'));
    }
    if (!preg_match('/^[a-z_0-9]+$/', trim($form_state
      ->getValue('form_key')))) {
      $form_state
        ->setErrorByName('form_key', $this
        ->t('Illegal character(s) in form ID.'));
    }
  }
  elseif (!preg_match('/\\W*([a-z_0-9]+)\\W+([a-z_0-9]+)\\W*/s', $form_state
    ->getValue('autocomplete'))) {
    $form_state
      ->setErrorByName('autocomplete', $this
      ->t('Auto-complete must be in the form "form_id:field_name", (one per line).'));
  }
}