You are here

public function IndexForm::validateForm in Elasticsearch Connector 8.7

Same name and namespace in other branches
  1. 8.2 src/Form/IndexForm.php \Drupal\elasticsearch_connector\Form\IndexForm::validateForm()
  2. 8.5 src/Form/IndexForm.php \Drupal\elasticsearch_connector\Form\IndexForm::validateForm()
  3. 8.6 src/Form/IndexForm.php \Drupal\elasticsearch_connector\Form\IndexForm::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/IndexForm.php, line 277

Class

IndexForm
Form controller for node type forms.

Namespace

Drupal\elasticsearch_connector\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $values = $form_state
    ->getValues();
  if (!preg_match('/^[a-z][a-z0-9_]*$/i', $values['index_id'])) {
    $form_state
      ->setErrorByName('name', t('Enter an index name that begins with a letter and contains only letters, numbers, and underscores.'));
  }
  if (!is_numeric($values['num_of_shards']) || $values['num_of_shards'] < 1) {
    $form_state
      ->setErrorByName('num_of_shards', t('Invalid number of shards.'));
  }
  if (!is_numeric($values['num_of_replica'])) {
    $form_state
      ->setErrorByName('num_of_replica', t('Invalid number of replica.'));
  }
}