You are here

public function BasicConsentStorage::registerConsent 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::registerConsent()

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.

Parameters

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 value

bool Returns TRUE when the consent has been stored successfully, FALSE on error.

Overrides ConsentStorageBase::registerConsent

File

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

Class

BasicConsentStorage
Provides a database storage for cookie consents.

Namespace

Drupal\eu_cookie_compliance\Plugin\ConsentStorage

Code

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;
}