diff --git a/web/modules/custom/sfgov_search/src/Form/GoogleSearchForm.php b/web/modules/custom/sfgov_search/src/Form/GoogleSearchForm.php index dc130e199..84e53bf19 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 dd2452942..8f065a405 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); }