CseResultsController.php in Google AdSense integration 8
File
src/Controller/CseResultsController.php
View source
<?php
namespace Drupal\adsense\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class CseResultsController 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() {
$config = $this
->config('adsense.settings');
$width = $config
->get('adsense_cse_frame_width');
$country = $config
->get('adsense_cse_country');
if ($config
->get('adsense_test_mode')) {
$content = [
'#theme' => 'adsense_ad',
'#content' => [
'#markup' => nl2br("Results\nwidth = {$width}\ncountry = {$country}"),
],
'#classes' => [
'adsense-placeholder',
],
'#width' => $width,
'#height' => 100,
];
}
else {
global $base_url;
$this
->getLogger('AdSense CSE v1')
->notice('Search keywords: %keyword', [
'%keyword' => urldecode($this->requestStack
->getCurrentRequest()->query
->get('q')),
]);
$content = [
'#theme' => 'adsense_cse_results',
'#width' => $width,
'#country' => $country,
'#script' => $base_url . '/' . drupal_get_path('module', 'adsense') . '/js/adsense_cse-v1.results.js',
];
}
return $content;
}
}