abstract class ConsentStorageBase in EU Cookie Compliance (GDPR Compliance) 8
Same name and namespace in other branches
- 2.0.x src/Plugin/ConsentStorageBase.php \Drupal\eu_cookie_compliance\Plugin\ConsentStorageBase
Provides a base class for a consent storage.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\eu_cookie_compliance\Plugin\ConsentStorageBase implements ConsentStorageInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ConsentStorageBase
See also
\Drupal\eu_cookie_compliance\Plugin\ConsentStorageInterface
\Drupal\eu_cookie_compliance\Plugin\ConsentStorageManager
\Drupal\eu_cookie_compliance\Plugin\ConsentStorageManagerInterface
1 file declares its use of ConsentStorageBase
- BasicConsentStorage.php in src/
Plugin/ ConsentStorage/ BasicConsentStorage.php
File
- src/
Plugin/ ConsentStorageBase.php, line 17
Namespace
Drupal\eu_cookie_compliance\PluginView source
abstract class ConsentStorageBase extends PluginBase implements ConsentStorageInterface {
/**
* The config factory.
*
* Subclasses should use the self::config() method, which may be overridden to
* address specific needs when loading config, rather than this property
* directly. See \Drupal\Core\Form\ConfigFormBase::config() for an example of
* this.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a ConsentStorageBase object.
*
* @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.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
}
/**
* {@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'));
}
/**
* {@inheritdoc}
*/
public function label() {
return $this->pluginDefinition['label'];
}
/**
* {@inheritdoc}
*/
public function description() {
return $this->pluginDefinition['description'];
}
/**
* Get status.
*
* @return bool
* Current status.
*/
public function getStatus() {
return TRUE;
}
/**
* Get the current revision of the privacy policy node.
*
* @return bool|int
* Returns the latest revision ID of the curreny privacy policy node, or
* FALSE if no priacy policy exists.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function getCurrentPolicyNodeRevision() {
$config = $this->configFactory
->get('eu_cookie_compliance.settings');
$cookie_policy_link = $config
->get('popup_link');
$cookie_policy_drupal_path = \Drupal::service('path_alias.manager')
->getPathByAlias($cookie_policy_link, \Drupal::languageManager()
->getCurrentLanguage()
->getId());
if (substr($cookie_policy_drupal_path, 0, 6) === '/node/') {
$node_id = explode('/', $cookie_policy_drupal_path)[2];
/** @var \Drupal\node\Entity\Node $node */
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load($node_id);
// Ensure the node has been loaded before accessing any properties.
if (!$node) {
return FALSE;
}
return $node
->getRevisionId();
}
return FALSE;
}
/**
* Register consent.
*
* In addition to the parameters passed to the function, consider storing the
* uid, ip address, timestamp and the current revision of the cookie policy.
*
* @param string $consent_type
* "banner" if the consent is given to the cookie banner or the form ID when
* consent is given on a form.
*
* @return bool
* Returns TRUE when the consent has been stored successfully, FALSE on
* error.
*/
public abstract function registerConsent($consent_type);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConsentStorageBase:: |
protected | property | The config factory. | |
ConsentStorageBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
ConsentStorageBase:: |
public | function |
Returns the consent storage description. Overrides ConsentStorageInterface:: |
|
ConsentStorageBase:: |
public | function | Get the current revision of the privacy policy node. | |
ConsentStorageBase:: |
public | function | Get status. | |
ConsentStorageBase:: |
public | function |
Returns the consent storage label. Overrides ConsentStorageInterface:: |
|
ConsentStorageBase:: |
abstract public | function | Register consent. | 1 |
ConsentStorageBase:: |
public | function |
Constructs a ConsentStorageBase object. Overrides PluginBase:: |
1 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |