Task #89176

Provide better way to traverse array in TS conditions

Added by Markus Klein about 1 month ago. Updated 2 days ago.

Status:
Under Review
Priority:
Should have
Assignee:
Category:
TypoScript
Target version:
-
Start date:
2019-09-14
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

[request.getQueryParams()['my_ext']['foo'] > 0]

conditions like these cause errors if my_ext is not set or if foo is not set.

For the first case a dirty workaround is:

[request.getQueryParams() && request.getQueryParams()['my_ext'] && request.getQueryParams()['my_ext']['foo'] > 0]

which still crashes for the case when foo is not set.

My suggestion to solve this is:

[traverse(request.getQueryParams(), 'my_ext/foo') > 0]

Related issues

Related to TYPO3 Core - Bug #88756: TypoScript – Symfony Expressions: request.getQueryParams() should do an "is defined" validation Rejected 2019-07-15
Related to TYPO3 Core - Bug #88252: Route Results are not available via TypoScript Closed 2019-04-30

History

#1 Updated by Markus Klein about 1 month ago

  • Related to Bug #88756: TypoScript – Symfony Expressions: request.getQueryParams() should do an "is defined" validation added

#2 Updated by Gerrit Code Review about 1 month ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61708

#3 Updated by Markus Klein 2 days ago

  • Related to Bug #88252: Route Results are not available via TypoScript added

#4 Updated by Wolfgang Klinger 2 days ago

I use this all the time and nothing crashes. What do you mean with crashes? An exception? A warning? A notice?

[request.getQueryParams()['tx_news_pi1'] && (request.getQueryParams()['tx_news_pi1'])['news'] > 0]

#5 Updated by Markus Klein 2 days ago

do you have URLs where tx_news_pi1|* but no tx_news_pi1|news is present?
(archive for instance)
Then you get errors.

Or, much simpler: TS is evaluated in BE context too (eg. belog module), which floods the logs.

Also available in: Atom PDF