You are here

public function GoogleCSEServices::sitesearchOptions in Google Custom Search Engine 8.3

Same name and namespace in other branches
  1. 8.2 src/GoogleCSEServices.php \Drupal\google_cse\GoogleCSEServices::sitesearchOptions()

Returns SiteSearch options.

2 calls to GoogleCSEServices::sitesearchOptions()
GoogleCSEServices::sitesearchDefault in src/GoogleCSEServices.php
Returns SiteSearch default value.
GoogleCSEServices::siteSearchForm in src/GoogleCSEServices.php
Returns SiteSearch options form item.

File

src/GoogleCSEServices.php, line 497

Class

GoogleCSEServices
Additional functions as services for Google CSE.

Namespace

Drupal\google_cse

Code

public function sitesearchOptions() {
  static $options;
  if (!isset($options)) {
    $options = [];
    if ($sites = preg_split('/[\\n\\r]+/', $this->CSEconfig
      ->get('configuration')['sitesearch'], -1, PREG_SPLIT_NO_EMPTY)) {
      $options[''] = ($var = $this->CSEconfig
        ->get('configuration')['sitesearch_option']) ? $var : t('Search the web');
      foreach ($sites as $site) {
        $site = preg_split('/[\\s]+/', trim($site), 2, PREG_SPLIT_NO_EMPTY);

        // Select options will be HTML-escaped.
        // Radio options will be XSS-filtered.
        $options[$site[0]] = isset($site[1]) ? $site[1] : t('Search %sitesearch', [
          '%sitesearch' => $site[0],
        ]);
      }
    }
  }
  return $options;
}