BasicConsentStorage.php in EU Cookie Compliance (GDPR Compliance) 2.0.x
File
src/Plugin/ConsentStorage/BasicConsentStorage.php
View source
<?php
namespace Drupal\eu_cookie_compliance\Plugin\ConsentStorage;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\eu_cookie_compliance\Plugin\ConsentStorageBase;
use Drupal\Component\Datetime\TimeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
class BasicConsentStorage extends ConsentStorageBase implements ContainerFactoryPluginInterface {
protected $time;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TimeInterface $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory);
$this->time = $time;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('datetime.time'));
}
public function registerConsent($consent_type) {
$revision_id = $this
->getCurrentPolicyNodeRevision();
$timestamp = $this->time
->getRequestTime();
$ip_address = \Drupal::request()
->getClientIp();
$uid = \Drupal::currentUser()
->id();
\Drupal::database()
->insert('eu_cookie_compliance_basic_consent')
->fields([
'uid' => $uid,
'ip_address' => $ip_address,
'timestamp' => $timestamp,
'revision_id' => $revision_id ? $revision_id : 0,
'consent_type' => $consent_type,
])
->execute();
return TRUE;
}
}