You are here

public function ClusterForm::validateForm in Elasticsearch Connector 8.6

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

Class

ClusterForm
Provides a form for the Cluster entity.

Namespace

Drupal\elasticsearch_connector\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $values = $form_state
    ->getValues();

  // TODO: Check for valid URL when we are submitting the form.
  // Set default cluster.
  $default = $this->clusterManager
    ->getDefaultCluster();
  if (empty($default) && !$values['default']) {
    $default = $this->clusterManager
      ->setDefaultCluster($values['cluster_id']);
  }
  elseif ($values['default']) {
    $default = $this->clusterManager
      ->setDefaultCluster($values['cluster_id']);
  }
  if ($values['default'] == 0 && !empty($default) && $default == $values['cluster_id']) {
    $this
      ->messenger()
      ->addWarning(t('There must be a default connection. %name is still the default
          connection. Please change the default setting on the cluster you wish
          to set as default.', array(
      '%name' => $values['name'],
    )));
  }
}