3 namespace Drupal\eu_cookie_compliance\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Symfony\Component\HttpFoundation\JsonResponse;
9 * Controller for JS call that stores consent.
11 class StoreConsent extends ControllerBase {
16 public function store($target) {
17 // Get list of all plugins.
18 $consent_storages = \Drupal::service('plugin.manager.eu_cookie_compliance.consent_storage');
19 // Get the currently active plugin.
20 $consent_storage_method = \Drupal::configFactory()
21 ->get('eu_cookie_compliance.settings')
22 ->get('consent_storage_method');
23 // If we're not going to log consent, return NULL.
24 if (!$consent_storage_method || $consent_storage_method == 'do_not_store') {
25 return new JsonResponse(NULL);
29 /* @var \Drupal\eu_cookie_compliance\Plugin\ConsentStorageInterface $consent_storage */
30 $consent_storage = $consent_storages->createInstance($consent_storage_method);
32 $result = $consent_storage->registerConsent($target);
34 return new JsonResponse($result);