Skip to content
Snippets Groups Projects
Commit 9fc10d1a authored by jeff cardwell's avatar jeff cardwell Committed by Polo Reynaga
Browse files

Issue #3159988 by Jeff Cardwell, gravelpot: Remove references to "Google CSE Advanced"

parent 7b9ead94
Branches
Tags 8.x-3.2
No related merge requests found
......@@ -135,7 +135,6 @@ class GoogleCSESearch extends ConfigurableSearchPluginBase implements Accessible
'safe' => '',
'custom_css' => '',
'custom_results_display' => 'results-only',
'use_adv' => 0,
];
return $configuration;
}
......@@ -168,64 +167,16 @@ class GoogleCSESearch extends ConfigurableSearchPluginBase implements Accessible
* {@inheritdoc}
*/
public function execute() {
$keys = $this->getKeywords();
// @todo $condition is an unused variable verify and remove it.
$conditions = $this->searchParameters['search_conditions'];
if ($this->configuration['use_adv']) {
$response = $this->googlecseservices->service($keys);
$results = $this->googlecseservices->responseResults($response[0], $keys, $conditions);
// Allow other modules to alter the keys.
$this->moduleHandler->alter('google_cse_searched_keys', $keys);
// Allow other modules to alter the results.
$this->moduleHandler->alter('google_cse_searched_results', $results);
return $results;
}
// This function must remain to satisfy the
// Drupal/search//Plugin/SearchInterface, but we have no use for it.
}
/**
* {@inheritdoc}
*/
public function buildResults() {
$results = $this->execute();
// @see https://www.drupal.org/node/2195739
if (!($this->configuration['use_adv'])) {
$output[] = ['#theme' => 'google_cse_results'];
return $output;
}
if (!$results) {
// No results found.
$output[] = ['#theme' => 'google_cse_search_noresults'];
}
if ($this->requestStack->getCurrentRequest()->query->has('page')) {
$current_page = $this->requestStack->getCurrentRequest()->query->get('page');
$number_results = t('Results @from to @to of @total matches.', [
'@from' => $current_page * 10,
'@to' => $current_page * 10 + 10,
'@total' => $GLOBALS['pager_total_items'][0],
]);
$output['prefix']['#markup'] = $number_results . '<ol class="search-results">';
}
foreach ($results as $entry) {
$output[] = [
'#theme' => 'search_result',
'#result' => $entry,
'#plugin_id' => $this->getPluginId(),
];
}
if ($this->requestStack->getCurrentRequest()->query->has('page')) {
// Important, add the pager.
$pager = ['#type' => 'pager'];
$output['suffix']['#markup'] = '</ol>' . $this->renderer->render($pager);
}
// Results are primarily generated by the Google API.
$output[] = ['#theme' => 'google_cse_results'];
return $output;
}
......@@ -244,21 +195,9 @@ class GoogleCSESearch extends ConfigurableSearchPluginBase implements Accessible
* {@inheritdoc}
*/
public function buildSearchUrlQuery(FormStateInterface $form_state) {
// Read keyword and advanced search information from the form values,
// and put these into the GET parameters.
$keys = trim($form_state->getValue('keys'));
if (!$this->configuration['use_adv']) {
return ['keys' => $keys];
}
// @TODO check usage of $here and $sitesearch
$sitesearch = NULL;
$here = FALSE;
return [
'keys' => $keys,
'cx' => $this->configuration['cx'],
'cof' => $here ? $this->configuration['cof_here'] : $this->configuration['cof_google'],
'sitesearch' => isset($sitesearch) ? $sitesearch : $this->googlecseservices->sitesearchDefault(),
] + $this->googlecseservices->advancedSettings();
return ['keys' => $keys];
}
/**
......@@ -575,19 +514,6 @@ class GoogleCSESearch extends ConfigurableSearchPluginBase implements Accessible
]),
];
$form['google_cse_adv'] = [
'#title' => $this->t('Google CSE Advanced'),
'#type' => 'details',
'#open' => TRUE,
];
$form['google_cse_adv']['use_adv'] = [
'#title' => t('Use advanced, ad-free version, search engine (You will need a paid account with Google)'),
'#type' => 'checkbox',
'#default_value' => $this->configuration['use_adv'] ?? '',
'#description' => $this->t('If enabled, search results will be fetch using Adv engine.'),
];
return $form;
}
......@@ -624,7 +550,6 @@ class GoogleCSESearch extends ConfigurableSearchPluginBase implements Accessible
$this->configuration['safe'] = $values['safe'];
$this->configuration['custom_css'] = $values['custom_css'];
$this->configuration['custom_results_display'] = $values['custom_results_display'];
$this->configuration['use_adv'] = $values['use_adv'];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment