You are here

public function StoreConsent::store in EU Cookie Compliance (GDPR Compliance) 2.0.x

Same name and namespace in other branches
  1. 8 src/Controller/StoreConsent.php \Drupal\eu_cookie_compliance\Controller\StoreConsent::store()

Store consent.

Parameters

string $target: The target.

Return value

JsonResponse Result of action.

1 string reference to 'StoreConsent::store'
eu_cookie_compliance.routing.yml in ./eu_cookie_compliance.routing.yml
eu_cookie_compliance.routing.yml

File

src/Controller/StoreConsent.php, line 22

Class

StoreConsent
Controller for JS call that stores consent.

Namespace

Drupal\eu_cookie_compliance\Controller

Code

public function store($target) {

  // Get list of all plugins.
  $consent_storages = \Drupal::service('plugin.manager.eu_cookie_compliance.consent_storage');

  // Get the currently active plugin.
  $consent_storage_method = \Drupal::configFactory()
    ->get('eu_cookie_compliance.settings')
    ->get('consent_storage_method');

  // If we're not going to log consent, return NULL.
  if (!$consent_storage_method || $consent_storage_method === 'do_not_store') {
    return new JsonResponse(NULL);
  }

  // Get plugin.

  /** @var \Drupal\eu_cookie_compliance\Plugin\ConsentStorageInterface $consent_storage */
  $consent_storage = $consent_storages
    ->createInstance($consent_storage_method);

  // Register consent.
  $result = $consent_storage
    ->registerConsent($target);

  // Return value.
  return new JsonResponse($result);
}