Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / eu_cookie_compliance / src / Controller / StoreConsent.php
1 <?php
2
3 namespace Drupal\eu_cookie_compliance\Controller;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Symfony\Component\HttpFoundation\JsonResponse;
7
8 /**
9  * Controller for JS call that stores consent.
10  */
11 class StoreConsent extends ControllerBase {
12
13   /**
14    * {@inheritdoc}
15    */
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);
26     }
27
28     // Get plugin.
29     /* @var \Drupal\eu_cookie_compliance\Plugin\ConsentStorageInterface $consent_storage */
30     $consent_storage = $consent_storages->createInstance($consent_storage_method);
31     // Register consent.
32     $result = $consent_storage->registerConsent($target);
33     // Return value.
34     return new JsonResponse($result);
35   }
36
37 }