setNewPreferencesCookie example

$allowedCookies = $this->cookieGroupCollection;

        foreach ($preferences['groups'] as $group) {
            foreach ($group['cookies'] as $cookie) {
                $cookieCollection = $allowedCookies->getGroupByName($group['name'])->getCookies();

                if ($this->hasCookieWithTechnicalName($cookieCollection$cookie['name'])) {
                    continue;
                }

                unset($preferences['groups'][$group['name']]['cookies'][$cookie['name']]);
                $this->setNewPreferencesCookie($request$response$preferences);
            }
        }

        return $preferences;
    }

    protected function hasCookieWithTechnicalName(CookieCollection $cookieCollection, string $technicalName): bool
    {
        return $cookieCollection->exists(static function Dstring $key, CookieStruct $cookieStruct) use ($technicalName) {
            return $cookieStruct->getName() === $technicalName;
        });
    }
Home | Imprint | This part of the site doesn't use cookies.