CookieConsentConfig
in package
Holds the cookie consent categories and their settings.
Values come from config/Shared/cookieConsent.neon (parameters.cookieConsent.*). This is
the single source of truth for both sides: the front cookie bar
(CookieBar) renders its modal
switches from it, and the admin (custom code and page scripts) builds the "cookie consent"
choice from it. Two separate lists could drift apart: the admin could offer a category the
bar does not, and its script would wait for consent forever.
IMPORTANT: adding a category is a code change, not just configuration. Besides the neon file it needs:
- translations
front.base.components.cookieBar.categories.<key>.titleand.descriptionin all languages (app/Locale/base/<locale>/front.<LOCALE>.neon), CONSENT_MODE_SIGNALSandCATEGORY_COOKIESinassets/js/components/cookie-bar.js(all themes) plus a webpack build, when the category maps to Google Consent Mode or deletes cookies on withdrawal,- a higher
revision.
IMPORTANT: that is why the list is not in the database and not editable in the admin. A category enabled without points 1 and 2 promises a choice nothing implements: the switch can be turned off and nothing happens.
Table of Contents
Properties
- $categories : array<string|int, mixed>
- $expirationDays : int
- $revision : int
Methods
- __construct() : mixed
- isSelectable() : bool
- Returns whether a category with this key exists and the visitor can toggle it.
- selectableKeys() : array<int, string>
- Returns the categories a visitor can toggle, that is, those that are not `readonly`.
Properties
$categories read-only
public
array<string|int, mixed>
$categories
= []
$expirationDays read-only
public
int
$expirationDays
= 182
$revision read-only
public
int
$revision
= 1
Methods
__construct()
public
__construct([array<int, array{key: string, readonly: bool}> $categories = [] ][, int $revision = 1 ][, int $expirationDays = 182 ]) : mixed
Parameters
- $categories : array<int, array{key: string, readonly: bool}> = []
-
Order matches the switches in the modal.
readonlymeans always granted (technically necessary) and the switch is locked. - $revision : int = 1
-
Consent version. Raising it invalidates all granted consents and the bar shows again. IMPORTANT: raise it when adding a category, otherwise people who already answered keep the new category silently denied and never see the bar again.
- $expirationDays : int = 182
-
Consent lifetime in days; after that the bar shows again.
isSelectable()
Returns whether a category with this key exists and the visitor can toggle it.
public
isSelectable(string $key) : bool
Parameters
- $key : string
Return values
boolselectableKeys()
Returns the categories a visitor can toggle, that is, those that are not `readonly`.
public
selectableKeys() : array<int, string>
This is the list for the custom code consent choice: necessary is always granted, so it
would be no different from "run always" and would only confuse.