Skip to content

Commit

Permalink
Merge pull request #45 from hphoeksma/master
Browse files Browse the repository at this point in the history
Fix: errors thrown when cookie is not set
  • Loading branch information
Nikdro authored Jan 4, 2023
2 parents 43ffdf1 + 7d988da commit 8c8f3bd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Classes/Controller/JavaScriptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,22 @@ function ($key) {
array_map(function ($dimension) { return current($dimension);}, $filteredDimensions)
);

$cookie = json_decode($this->request->getHttpRequest()->getCookieParams()[$this->cookieName], true);
$cookie = !empty($this->request->getHttpRequest()->getCookieParams()) && isset($this->request->getHttpRequest()->getCookieParams()[$this->cookieName]) ? json_decode($this->request->getHttpRequest()->getCookieParams()[$this->cookieName], true) : null;
$consents = $cookie['consents'][$dimensionIdentifier] ?? $cookie['consents']['default'] ?? $cookie['consents'] ?? [];
$siteNode = $this->contextFactory->create(['dimensions' => $dimensions])->getCurrentSiteNode();

$cacheIdentifier = 'kd_gdpr_cc_' . sha1(json_encode($consents) . $dimensionIdentifier . $siteNode->getIdentifier());

$q = new FlowQuery([$siteNode]);

$consentDate = new \DateTime($cookie['consentDates'][$dimensionIdentifier] ?? $cookie['consentDate']);
if (isset($cookie['consentDates'][$dimensionIdentifier])) {
$consentDate = new \DateTime($cookie['consentDates'][$dimensionIdentifier]);
} elseif (isset($cookie['consentDate'])) {
$consentDate = new \DateTime($cookie['consentDate']);
} else {
$consentDate = new \DateTime('now');
}

$cookieSettings = $q->find('[instanceof KaufmannDigital.GDPR.CookieConsent:Content.CookieSettings]')->get(0);

if (!$cookieSettings instanceof NodeInterface) {
Expand Down

0 comments on commit 8c8f3bd

Please sign in to comment.