TYPO3 condition not working as expected from cookies manual
The manual gives an old condition, that is no more working with PHP 8.2 and TYPO3 12
TYPO3 is giving also the following code:
[request && request.getCookieParams()['foo'] == 1]
But in my case with PHP8.2 I got an error that "foo" or "tx_cookies-type-analytics" is not part of the array. It is strange that a condition is not automatically going to false when a array index-value is missing. If the cookie with the appropriate name is there it works.
My solution is to use "traverse":
[traverse(request.getCookieParams(), 'tx_cookies-type-analytics') == 1 or traverse(request.getCookieParams(), 'tx_cookies_accepted') == 1]
This seems to work.
But there should also be a solution with the null coalescing operator "?" but couldn't find out where and how to place it.
Here an example from the TYPO3 docs: null-safe operator
New in version 12.1.
Using the null-safe operator is possible when accessing properties on objects which might not be available in some context, for example TSFE in the backend:
Previously
[getTSFE() && getTSFE().id == 123]
Now
[getTSFE()?.id == 123]