Skip to content

Commit

Permalink
Merge pull request #64 from palantirnet/PL-10-Add-config-option-to-al…
Browse files Browse the repository at this point in the history
…low-for-empty-search

Pl 10 add config option to allow for empty search
  • Loading branch information
froboy authored Dec 16, 2018
2 parents 7cf3343 + b36894d commit 38d3deb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions search_api_federated_solr.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ search:
version: 1.x
css:
theme:
https://cdn.jsdelivr.net/gh/palantirnet/[email protected].9/css/main.cf6a58ce.css: { type: external, minified: true }
https://cdn.jsdelivr.net/gh/palantirnet/[email protected].10/css/main.cf6a58ce.css: { type: external, minified: true }
js:
https://cdn.jsdelivr.net/gh/palantirnet/[email protected].9/js/main.b294abb7.js: {
https://cdn.jsdelivr.net/gh/palantirnet/[email protected].10/js/main.d41fc3fe.js: {
preprocess: false,
minified: true,
}
5 changes: 5 additions & 0 deletions src/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public function searchPage() {
$federated_search_app_config['noResults'] = $no_results;
}

// OPTIONAL: The text to display when a search returns no results.
if ($show_empty_search_results = $config->get('content.show_empty_search_results')) {
$federated_search_app_config['showEmptySearchResults'] = $show_empty_search_results;
}

// OPTIONAL: The number of search results to show per page.
if ($rows = $config->get('results.rows')) {
$federated_search_app_config['rows'] = intval($rows);
Expand Down
12 changes: 12 additions & 0 deletions src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
],
];

$form['show_empty_search_results'] = [
'#type' => 'checkbox',
'#title' => $this->t('Show results for empty search'),
'#default_value' => $config->get('content.show_empty_search_results'),
'#description' => $this
->t(' When checked, this option allows users to see all results when no search term is entered. By default, empty searches are disabled and yield no results.'),
];

$form['no_results_text'] = [
'#type' => 'textfield',
'#title' => $this->t('No results text'),
Expand Down Expand Up @@ -180,6 +188,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$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).
Expand Down

0 comments on commit 38d3deb

Please sign in to comment.