CustomSearchV2Ad.php in Google AdSense integration 8
File
src/Plugin/AdsenseAd/CustomSearchV2Ad.php
View source
<?php
namespace Drupal\adsense\Plugin\AdsenseAd;
use Drupal\adsense\SearchAdBase;
use Drupal\adsense\PublisherId;
class CustomSearchV2Ad extends SearchAdBase {
private $slot;
public function __construct(array $configuration, $plugin_id = '', $plugin_definition = NULL, $config_factory = NULL, $module_handler = NULL, $current_user = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory, $module_handler, $current_user);
$this->slot = !empty($configuration['slot']) ? $configuration['slot'] : '';
}
public function getAdPlaceholder() {
if (!empty($this->slot)) {
$client = PublisherId::get();
$content = "CSE v2\ncx = partner-{$client}:{$this->slot}";
return [
'#content' => [
'#markup' => nl2br($content),
],
'#format' => 'Search Box v2',
];
}
return [];
}
public function getAdContent() {
if (!empty($this->slot)) {
$client = PublisherId::get();
$this->moduleHandler
->alter('adsense', $client);
return [
'#theme' => 'adsense_cse_v2_searchbox',
'#client' => $client,
'#slot' => $this->slot,
];
}
return [];
}
}