You are here

public function SearchApiSolrBackend::submitConfigurationForm in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::submitConfigurationForm()
  2. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::submitConfigurationForm()
  3. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::submitConfigurationForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PluginFormInterface::submitConfigurationForm

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 389

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  $this->configuration['connector'] = $form_state
    ->get('connector');
  $connector = $this
    ->getSolrConnector();
  if ($connector instanceof PluginFormInterface) {
    $connector_form_state = SubformState::createForSubform($form['connector_config'], $form, $form_state);
    $connector
      ->submitConfigurationForm($form['connector_config'], $connector_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['advanced'];
  $values += $values['multisite'];
  if (!empty($values['autocomplete'])) {
    $values += $values['autocomplete'];
  }
  else {
    $defaults = $this
      ->defaultConfiguration();
    $values['suggest_suffix'] = $defaults['suggest_suffix'];
    $values['suggest_corrections'] = $defaults['suggest_corrections'];
    $values['suggest_words'] = $defaults['suggest_words'];
  }

  // Highlighting retrieved data only makes sense when we retrieve data from
  // the Solr backend.
  $values['highlight_data'] &= $values['retrieve_data'];
  foreach ($values as $key => $value) {
    $form_state
      ->setValue($key, $value);
  }

  // Clean-up the form to avoid redundant entries in the stored configuration.
  $form_state
    ->unsetValue('advanced');
  $form_state
    ->unsetValue('multisite');
  $form_state
    ->unsetValue('autocomplete');

  // The server description is a #type item element, which means it has a
  // value, do not save it.
  $form_state
    ->unsetValue('server_description');
  $this
    ->traitSubmitConfigurationForm($form, $form_state);

  // Delete cached endpoint data.
  \Drupal::state()
    ->delete('search_api_solr.endpoint.data');
}