Skip to content

Commit

Permalink
chore: add checkbox to redirect to google search if needed (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
aekong authored Jan 8, 2025
1 parent 55e259c commit b7f8388
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 15 additions & 5 deletions web/modules/custom/sfgov_search/src/Form/GoogleSearchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ 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',
'#size' => '5',
'#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);
}
Expand All @@ -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);
}
Expand Down

1 comment on commit b7f8388

@aekong
Copy link
Collaborator Author

@aekong aekong commented on b7f8388 Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visit Site

Created multidev environment ci-20896 for sfgov.

Please sign in to comment.