You are here

public function IndexForm::validate in Elasticsearch Connector 8

File

src/Form/IndexForm.php, line 215
Contains \Drupal\elasticsearch_connector\Form\IndexForm.

Class

IndexForm
Form controller for node type forms.

Namespace

Drupal\elasticsearch_connector\Form

Code

public function validate(array $form, FormStateInterface $form_state) {
  parent::validate($form, $form_state);
  $values = $form_state
    ->getValues();
  if (!preg_match('/^[a-z][a-z0-9_]*$/i', $values['name'])) {
    $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.'));
  }
}