You are here

public function BasicAuthTrait::submitConfigurationForm in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/BasicAuthTrait.php \Drupal\search_api_solr\SolrConnector\BasicAuthTrait::submitConfigurationForm()
  2. 4.x src/SolrConnector/BasicAuthTrait.php \Drupal\search_api_solr\SolrConnector\BasicAuthTrait::submitConfigurationForm()

File

src/SolrConnector/BasicAuthTrait.php, line 58

Class

BasicAuthTrait
Basic auth functionality for a Solr connector.

Namespace

Drupal\search_api_solr\SolrConnector

Code

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

  // Since the form is nested into another, we can't simply use #parents for
  // doing this array restructuring magic. (At least not without creating an
  // unnecessary dependency on internal implementation.)
  $values += $values['auth'];

  // For password fields, there is no default value, they're empty by default.
  // Therefore we ignore empty submissions if the user didn't change either.
  if ($values['password'] === '' && isset($this->configuration['username']) && $values['username'] === $this->configuration['username']) {
    $values['password'] = $this->configuration['password'];
  }
  foreach ($values['auth'] as $key => $value) {
    $form_state
      ->setValue($key, $value);
  }

  // Clean-up the form to avoid redundant entries in the stored configuration.
  $form_state
    ->unsetValue('auth');
  parent::submitConfigurationForm($form, $form_state);
}