powermail icon indicating copy to clipboard operation
powermail copied to clipboard

Use typesafe getTSFE in TypoScript conditions (to prevent unnecessary log messages)

Open sypets opened this issue 1 year ago • 0 comments

[getTSFE().type == 31311 || getTSFE().type == 31312 || getTSFE().type == 31319]

https://github.com/in2code-de/powermail/blob/77077c6965f3701de9062d0208b4fb6b5e0e7713/Configuration/TypoScript/Powermail_Frontend/setup.typoscript#L116C1-L116C80

should be

[getTSFE()?.type == 31311 || getTSFE()?.type == 31312 || getTSFE()?.type == 31319]

see official TYPO3 docs:

Using the getTSFE() function, developers have to ensure that "TSFE" is available before accessing its properties. A missing "TSFE", for example, in backend context, does no longer automatically evaluate the whole condition to false. Instead, the function returns null, which can be checked using either [getTSFE() && getTSFE().id == 17] or the null-safe operator [getTSFE()?.id == 17].

https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/Conditions/Index.html#gettsfe

Versions

  • TYPO3 11.5.32
  • powermail: 10.7.3 (but problem also exists in latest "master"

Context

have multiple warnings such as

Core: Error handler (FE): PHP Warning: Undefined array key "type" in /var/www/mysite/releases/152/vendor/symfony/expression-language/Node/GetAttrNode.php line 97 in logs. Tracked this down to most likely be result of condition in powermail (not 100% sure), see also https://forge.typo3.org/issues/98515

sypets avatar Nov 03 '23 06:11 sypets