You are here

function template_preprocess_google_cse_results in Google Custom Search Engine 8.2

Same name and namespace in other branches
  1. 8.3 google_cse.theme.inc \template_preprocess_google_cse_results()
  2. 6 google_cse.theme.inc \template_preprocess_google_cse_results()
  3. 7.3 google_cse.theme.inc \template_preprocess_google_cse_results()
  4. 7 google_cse.theme.inc \template_preprocess_google_cse_results()
  5. 7.2 google_cse.theme.inc \template_preprocess_google_cse_results()

The search results page can be themed/customized.

File

./google_cse.theme.inc, line 47
Themeable functions for Google Custom Search Engine.

Code

function template_preprocess_google_cse_results(&$variables) {
  $config = \Drupal::config('search.page.google_cse_search');
  $variables['results_searchbox_form'] = $variables['form'] ? \Drupal::formBuilder()
    ->getForm('Drupal\\google_cse\\Form\\GoogleCSESearchBoxForm') : '';
  $variables['cse_tag'] = google_cse_get_cse_tag();
  $url = Url::fromUri('http://' . $config
    ->get('configuration')['domain'] . '/cse', [
    'query' => [
      'keys' => \Drupal::request()->query
        ->get('keys'),
    ],
  ]);
  $variables['noscript'] = t('@google, or enable JavaScript to view them here.', [
    '@google' => Link::fromTextAndUrl('View the results at Google', $url)
      ->toString(),
  ]);
  $variables['prefix'] = Xss::filterAdmin($config
    ->get('configuration')['results_prefix']);
  $variables['suffix'] = Xss::filterAdmin($config
    ->get('configuration')['results_suffix']);
  if (google_cse_validate_request()) {
    $variables['#attached']['library'][] = 'google_cse/googlecseResults';

    // Adds a custom library by google_cse_library_info_build()
    if (!empty($config
      ->get('configuration')['custom_css'])) {
      $variables['#attached']['library'][] = 'google_cse/googlecseCustomcss';
    }
  }
}