You are here

public function CseV2ResultsController::display in Google AdSense integration 8

Display the search results page.

Parameters

string $slot: CSE slot ID.

Return value

array Markup for the page with the search results.

1 string reference to 'CseV2ResultsController::display'
adsense.routing.yml in ./adsense.routing.yml
adsense.routing.yml

File

src/Controller/CseV2ResultsController.php, line 50

Class

CseV2ResultsController
Controller for the Custom Search Engine v2 results page.

Namespace

Drupal\adsense\Controller

Code

public function display($slot) {
  $config = $this
    ->config('adsense.settings');
  $client = PublisherId::get();
  $this
    ->moduleHandler()
    ->alter('adsense', $client);
  if ($config
    ->get('adsense_test_mode')) {
    $content = [
      '#theme' => 'adsense_ad',
      '#content' => [
        '#markup' => nl2br("Results\ncx = partner-{$client}:{$slot}"),
      ],
      '#classes' => [
        'adsense-placeholder',
      ],
      '#height' => 100,
    ];
  }
  else {

    // Log the search keys.
    $this
      ->getLogger('AdSense CSE v2')
      ->notice('Search keywords: %keyword', [
      '%keyword' => urldecode($this->requestStack
        ->getCurrentRequest()->query
        ->get('q')),
    ]);
    $content = [
      '#theme' => 'adsense_cse_v2_results',
      '#client' => $client,
      '#slot' => $slot,
    ];
  }
  return $content;
}