You are here

class BasicConsentStorage in EU Cookie Compliance (GDPR Compliance) 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/ConsentStorage/BasicConsentStorage.php \Drupal\eu_cookie_compliance\Plugin\ConsentStorage\BasicConsentStorage

Provides a database storage for cookie consents.

Plugin annotation


@ConsentStorage(
  id = "basic",
  name = @Translation("Basic storage"),
  description = @Translation("Basic storage")
)

Hierarchy

Expanded class hierarchy of BasicConsentStorage

File

src/Plugin/ConsentStorage/BasicConsentStorage.php, line 20

Namespace

Drupal\eu_cookie_compliance\Plugin\ConsentStorage
View source
class BasicConsentStorage extends ConsentStorageBase implements ContainerFactoryPluginInterface {

  /**
   * The time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected $time;

  /**
   * BasicConsentStorage constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The time service.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BasicConsentStorage::$time protected property The time service.
BasicConsentStorage::create public static function Creates an instance of the plugin. Overrides ConsentStorageBase::create
BasicConsentStorage::registerConsent public function Register consent. Overrides ConsentStorageBase::registerConsent
BasicConsentStorage::__construct public function BasicConsentStorage constructor. Overrides ConsentStorageBase::__construct
ConsentStorageBase::$configFactory protected property The config factory.
ConsentStorageBase::description public function Returns the consent storage description. Overrides ConsentStorageInterface::description
ConsentStorageBase::getCurrentPolicyNodeRevision public function Get the current revision of the privacy policy node.
ConsentStorageBase::getStatus public function Get status.
ConsentStorageBase::label public function Returns the consent storage label. Overrides ConsentStorageInterface::label
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.