public function SearchApiFederatedSolrSearchAppSettingsForm::submitForm in Search API Federated Solr 8.3
Same name and namespace in other branches
- 8 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 659 - 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 config settings for hidden filter/facets.
$hide_search_site = $form_state
->getValue('hide_site_name');
$config
->set('facet.site_name.is_hidden', $hide_search_site);
$hide_type = $form_state
->getValue('hide_type');
$config
->set('facet.federated_type.is_hidden', $hide_type);
$hide_terms = $form_state
->getValue('hide_terms');
$config
->set('facet.federated_terms.is_hidden', $hide_terms);
$hide_date = $form_state
->getValue('hide_date');
$config
->set('filter.federated_date.is_hidden', $hide_date);
// 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);
// Set the allowed sites list.
$set_allowed_sites = $form_state
->getValue('set_allowed_sites');
$config
->set('facet.site_name.allowed_sites', $set_allowed_sites);
$search_api_index = $form_state
->getValue('search_index');
$config
->set('index.id', $search_api_index);
// Determine whether or not we should be using the proxy.
$proxy_is_disabled = $form_state
->getValue('disable_query_proxy');
$config
->set('proxy.isDisabled', $proxy_is_disabled);
// Set the Basic Auth username and password.
$username = $form_state
->getValue('username');
$password = $form_state
->getValue('password');
$config
->set('index.username', $username);
$config
->set('index.password', $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'));
// Set autocomplete options.
$autocomplete_is_enabled = $form_state
->getValue('autocomplete_is_enabled');
$config
->set('autocomplete.isEnabled', $form_state
->getValue('autocomplete_is_enabled'));
// If enabled, set the autocomplete options.
if ($autocomplete_is_enabled) {
// Cache form values that we'll use more than once.
$autocomplete_mode = $form_state
->getValue('autocomplete_mode');
// Determine the url to be used for autocomplete queries based on proxy flag.
$proxy_is_disabled = $form_state
->getValue('autocomplete_disable_query_proxy');
$autocomplete_direct_url = $proxy_is_disabled ? $form_state
->getValue('autocomplete_direct_url') : '';
// Default to the form values
$autocomplete_username = $form_state
->getValue('autocomplete_username');
$autocomplete_password = $form_state
->getValue('autocomplete_password');
$use_search_app_creds = $form_state
->getValue('autocomplete_use_search_app_creds');
// Add basic auth credentials
if ($use_search_app_creds) {
$autocomplete_username = $username;
$autocomplete_password = $password;
}
// Set the actual autocomplete config options.
$config
->set('autocomplete.proxy.isDisabled', $proxy_is_disabled);
$config
->set('autocomplete.direct.url', $autocomplete_direct_url);
$config
->set('autocomplete.appendWildcard', $form_state
->getValue('autocomplete_is_append_wildcard'));
$config
->set('autocomplete.use_search_app_creds', $use_search_app_creds);
$config
->set('autocomplete.username', $autocomplete_username);
$config
->set('autocomplete.password', $autocomplete_password);
$config
->set('autocomplete.suggestionRows', $form_state
->getValue('autocomplete_suggestion_rows'));
$config
->set('autocomplete.numChars', $form_state
->getValue('autocomplete_num_chars'));
if ($autocomplete_mode) {
$config
->set('autocomplete.mode', $autocomplete_mode);
$title_text_config_key = 'autocomplete.' . $autocomplete_mode . '.titleText';
$config
->set($title_text_config_key, $form_state
->getvalue('autocomplete_mode_title_text'));
$hide_directions_config_key = 'autocomplete.' . $autocomplete_mode . '.hideDirectionsText';
$config
->set($hide_directions_config_key, $form_state
->getValue('autocomplete_mode_hide_directions'));
}
}
$config
->save();
if ($rebuild_routes) {
// Rebuild the routing information without clearing all the caches.
\Drupal::service('router.builder')
->rebuild();
}
parent::submitForm($form, $form_state);
}