public function SearchApiFederatedSolrSearchAppSettingsForm::submitForm in Search API Federated Solr 8
Same name and namespace in other branches
- 8.3 src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php \Drupal\search_api_federated_solr\Form\SearchApiFederatedSolrSearchAppSettingsForm::submitForm()
- 8.2 src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php \Drupal\search_api_federated_solr\Form\SearchApiFederatedSolrSearchAppSettingsForm::submitForm()
- 4.x src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php \Drupal\search_api_federated_solr\Form\SearchApiFederatedSolrSearchAppSettingsForm::submitForm()
Form submission 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 ConfigFormBase::submitForm
File
- src/
Form/ SearchApiFederatedSolrSearchAppSettingsForm.php, line 170 - Contains \Drupal\search_api_solr_federated\Form\SearchApiFederatedSolrSearchAppSettingsForm.
Class
- SearchApiFederatedSolrSearchAppSettingsForm
- Class SearchApiFederatedSolrSearchAppSettingsForm.
Namespace
Drupal\search_api_federated_solr\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Retrieve the search app configuration.
$config = $this->configFactory
->getEditable('search_api_federated_solr.search_app.settings');
// Set the search app path.
$path = $form_state
->getValue('path');
$current_path = $config
->get('path');
$rebuild_routes = FALSE;
if ($path && $path !== $current_path) {
$config
->set('path', $path);
$rebuild_routes = TRUE;
}
// Set the search results page title.
$page_title = $form_state
->getValue('page_title');
$config
->set('page_title', $page_title);
// Set the search app config setting for the default search site flag.
$set_search_site = $form_state
->getValue('set_search_site');
$config
->set('facet.site_name.set_default', $set_search_site);
// Set the search app configuration setting for the default search site flag.
$show_empty_search_results = $form_state
->getValue('show_empty_search_results');
$config
->set('content.show_empty_search_results', $show_empty_search_results);
// Get the id of the chosen index.
$search_index = $form_state
->getValue('search_index');
// Save the selected index option in search app config (for form state).
$config
->set('index.id', $search_index);
// Get the index configuration object.
$index_config = \Drupal::config('search_api.index.' . $search_index);
$site_name_property = $index_config
->get('field_settings.site_name.configuration.site_name');
$config
->set('index.has_site_name_property', $site_name_property ? TRUE : FALSE);
// Get the id of the chosen index's server.
$index_server = $index_config
->get('server');
// Get the server url.
$server_config = \Drupal::config('search_api.server.' . $index_server);
$server = $server_config
->get('backend_config.connector_config');
// Get the required server config field data.
$server_url = $server['scheme'] . '://' . $server['host'] . ':' . $server['port'];
// Check for the non-required server config field data before appending.
$server_url .= $server['path'] ?: '';
$server_url .= $server['core'] ? '/' . $server['core'] : '';
// Append the request handler.
$server_url .= '/select';
// Set the search app configuration setting for the solr backend url.
$config
->set('index.server_url', $server_url);
// Set the Basic Auth username and password.
$config
->set('index.username', $form_state
->getValue('username'));
$config
->set('index.password', $form_state
->getValue('password'));
// Set the no results text.
$config
->set('content.no_results', $form_state
->getValue('no_results_text'));
// Set the search prompt text.
$config
->set('content.search_prompt', $form_state
->getValue('search_prompt_text'));
// Set the number of rows.
$config
->set('results.rows', $form_state
->getValue('rows'));
// Set the number of pagination buttons.
$config
->set('pagination.buttons', $form_state
->getValue('page_buttons'));
$config
->save();
if ($rebuild_routes) {
// Rebuild the routing information without clearing all the caches.
\Drupal::service('router.builder')
->rebuild();
}
parent::submitForm($form, $form_state);
}