You are here

public function GoogleCSESearch::buildSearchUrlQuery in Google Custom Search Engine 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Search/GoogleCSESearch.php \Drupal\google_cse\Plugin\Search\GoogleCSESearch::buildSearchUrlQuery()

Builds the URL GET query parameters array for search.

When the search form is submitted, a redirect is generated with the search input as GET query parameters. Plugins using the searchFormAlter() method to add form elements to the search form will need to override this method to gather the form input and add it to the GET query parameters.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The form state, with submitted form information.

Return value

array An array of GET query parameters containing all relevant form values to process the search. The 'keys' element must be present in order to trigger generation of search results, even if it is empty or unused by the search plugin.

Overrides SearchPluginBase::buildSearchUrlQuery

See also

SearchInterface::searchFormAlter()

File

src/Plugin/Search/GoogleCSESearch.php, line 246

Class

GoogleCSESearch
Handles searching for node entities using the Search module index.

Namespace

Drupal\google_cse\Plugin\Search

Code

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();
}