You are here

function template_preprocess_google_cse_results in Google Custom Search Engine 8.3

Same name and namespace in other branches
  1. 8.2 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 46
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();
  $configured_domain = $config
    ->get('configuration')['domain'];
  $domain = !empty($configured_domain) ? $configured_domain : $_SERVER['HTTP_HOST'];
  $protocol = \Drupal::service('google_cse.services')
    ->getProtocol();
  $url = Url::fromUri($protocol . $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'] = [
    '#markup' => $config
      ->get('configuration')['results_prefix'],
  ];
  $variables['suffix'] = [
    '#markup' => $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';
    }
  }
}