CookieDeclarationBlock.php in Cookiebot - Cookie consent, Cookie monitoring and Cookie control 8
File
src/Plugin/Block/CookieDeclarationBlock.php
View source
<?php
namespace Drupal\cookiebot\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CookieDeclarationBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $configFactory;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'));
}
public function build() {
$build = [];
$config = $this->configFactory
->get('cookiebot.settings');
$cbid = $config
->get('cookiebot_cbid');
if (empty($cbid)) {
return $build;
}
$build['cookie_declaration_block'] = [
'#theme' => 'cookiebot_declaration',
'#cookiebot_src' => 'https://consent.cookiebot.com/' . $cbid . '/cd.js',
];
return $build;
}
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), [
'cookiebot:cbid',
]);
}
}