From cc5b2bae57f9fd276f13f9634d0050e41cf22821 Mon Sep 17 00:00:00 2001 From: ant Date: Wed, 8 Jan 2025 11:47:35 -0800 Subject: [PATCH] chore: add checkbox to redirect to google search if needed --- .../src/Form/GoogleSearchForm.php | 20 ++++++++++++++----- .../src/Form/SfGovSearchConfigurationForm.php | 8 ++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/web/modules/custom/sfgov_search/src/Form/GoogleSearchForm.php b/web/modules/custom/sfgov_search/src/Form/GoogleSearchForm.php index dc130e199f..84e53bf199 100644 --- a/web/modules/custom/sfgov_search/src/Form/GoogleSearchForm.php +++ b/web/modules/custom/sfgov_search/src/Form/GoogleSearchForm.php @@ -92,11 +92,21 @@ public function buildForm(array $form, FormStateInterface $form_state) { } public function submitForm(array &$form, FormStateInterface $form_state) { + $config = \Drupal::config('sfgov_search.settings'); + $redirect_google = $config->get('redirect_google'); $search = $form_state->getValues()['keys']; - $google_search_url = \Drupal\Core\Url::fromUri('https://www.google.com/search', [ - 'query' => ['q' => $search . ' site:sf.gov OR site:sfgov.org'], - ])->toString(); - $response = new RedirectResponse($google_search_url); - $response->send(); + + if ($redirect_google) { + $google_search_url = \Drupal\Core\Url::fromUri('https://www.google.com/search', [ + 'query' => ['q' => $search . ' site:sf.gov OR site:sfgov.org'], + ])->toString(); + $response = new RedirectResponse($google_search_url); + $response->send(); + } else { + $form_state->setRedirect('search.view_google_json_api_search', ['keys' => $search], [ + 'language' => $this->languageManager->getCurrentLanguage(), + ]); + } + } } diff --git a/web/modules/custom/sfgov_search/src/Form/SfGovSearchConfigurationForm.php b/web/modules/custom/sfgov_search/src/Form/SfGovSearchConfigurationForm.php index dd24529426..8f065a405e 100644 --- a/web/modules/custom/sfgov_search/src/Form/SfGovSearchConfigurationForm.php +++ b/web/modules/custom/sfgov_search/src/Form/SfGovSearchConfigurationForm.php @@ -49,6 +49,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => $this->t('Funnelback collection name'), '#options' => $options, '#default_value' => $config->get('search_collection'), + '#disabled' => true, ]; $form['qie_influence'] = [ '#type' => 'textfield', @@ -56,6 +57,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#maxlength' => '3', '#title' => $this->t('QIE influence (between 0 - 1, eg: 0.7)'), '#default_value' => $config->get('qie_influence'), + '#disabled' => true, + ]; + $form['redirect_google'] = [ + '#type' => 'checkbox', + '#title' => 'Redirect search form submission to google', + '#default_value' => $config->get('redirect_google'), ]; return parent::buildForm($form, $form_state); } @@ -64,6 +71,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config(self::SETTINGS) ->set('search_collection', $form_state->getValue('search_collection_name')) ->set('qie_influence', $form_state->getValue('qie_influence')) + ->set('redirect_google', $form_state->getValue('redirect_google')) ->save(); parent::submitForm($form, $form_state); }