CseV2ResultsController.php in Google AdSense integration 8
File
src/Controller/CseV2ResultsController.php
View source
<?php
namespace Drupal\adsense\Controller;
use Drupal\adsense\PublisherId;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class CseV2ResultsController extends ControllerBase {
protected $requestStack;
public function __construct(RequestStack $request_stack) {
$this->requestStack = $request_stack;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('request_stack'));
}
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 {
$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;
}
}