Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / eu_cookie_compliance / src / Plugin / ConsentStorage / BasicConsentStorage.php
diff --git a/web/modules/contrib/eu_cookie_compliance/src/Plugin/ConsentStorage/BasicConsentStorage.php b/web/modules/contrib/eu_cookie_compliance/src/Plugin/ConsentStorage/BasicConsentStorage.php
new file mode 100644 (file)
index 0000000..ce1368a
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace Drupal\eu_cookie_compliance\Plugin\ConsentStorage;
+
+use Drupal\eu_cookie_compliance\Plugin\ConsentStorageBase;
+use Drupal\Core\Config\ConfigFactoryInterface;
+
+/**
+ * Provides a database storage for cookie consents.
+ *
+ * @ConsentStorage(
+ *   id = "basic",
+ *   name = @Translation("Basic storage"),
+ *   description = @Translation("Basic storage")
+ * )
+ */
+class BasicConsentStorage extends ConsentStorageBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(array $configuration, $plugin_id = NULL, $plugin_definition = NULL, ConfigFactoryInterface $config_factory = NULL) {
+    return parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function registerConsent($consent_type) {
+    $revision_id = $this->getCurrentPolicyNodeRevision();
+    $timestamp = time();
+    $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;
+  }
+
+}