Task #89176

Provide better way to traverse array in TS conditions

Added by Markus Klein 4 months ago. Updated 15 days ago.

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

100%

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

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
Related to TYPO3 Core - Bug #88928: routeEnhancers and GP conditions (TS) not working Needs Feedback 2019-08-07

Associated revisions

Revision 84f05982 (diff)
Added by Markus Klein 15 days ago

[TASK] Add a function to safely traverse arrays in TS conditions

Example:
[traverse(request.getQueryParams(), 'tx_news_pi/news') > 0]

Resolves: #89176
Releases: master, 9.5
Change-Id: Ic589f68382951c203afa5ad6a7bc16fbddbc20b2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61708
Tested-by: Susanne Moog <>
Tested-by: TYPO3com <>
Tested-by: Daniel Goerz <>
Reviewed-by: Susanne Moog <>
Reviewed-by: Daniel Goerz <>

Revision 3f8c961e (diff)
Added by Markus Klein 15 days ago

[TASK] Add a function to safely traverse arrays in TS conditions

Example:
[traverse(request.getQueryParams(), 'tx_news_pi/news') > 0]

Resolves: #89176
Releases: master, 9.5
Change-Id: Ic589f68382951c203afa5ad6a7bc16fbddbc20b2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62857
Tested-by: TYPO3com <>
Tested-by: Daniel Goerz <>
Reviewed-by: Daniel Goerz <>

History

#1 Updated by Markus Klein 4 months ago

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

#2 Updated by Gerrit Code Review 4 months 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 3 months ago

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

#4 Updated by Wolfgang Klinger 3 months 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 3 months 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.

#6 Updated by Sven Juergens about 2 months ago

hi,
how are the chances that this comes in the core?

Sorry, but this style of writing conditions are crap

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

technically speaking, using Symfony ExpressionLanguage is a big plus, no question about it.

But if something like that

[globalVar = GP:my_ext|foo> 0]

becoming something like this

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

than it's not a friendly system. The learning curve is quite high for beginners as far as TypoScript is concerned. But that makes it a lot harder to use the system. And in my opinion, TypoScript is still one of the great features of TYPO3. Precisely because of the conditions one is as flexible as in no other system.

#7 Updated by Gerrit Code Review 15 days ago

Patch set 2 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

#8 Updated by Markus Klein 15 days ago

  • Related to Bug #88928: routeEnhancers and GP conditions (TS) not working added

#9 Updated by Susanne Moog 15 days ago

  • Sprint Focus set to On Location Sprint

#10 Updated by Gerrit Code Review 15 days ago

Patch set 3 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

#11 Updated by Gerrit Code Review 15 days ago

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

#12 Updated by Markus Klein 15 days ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#13 Updated by Gerrit Code Review 15 days ago

  • Status changed from Resolved to Under Review

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

#14 Updated by Markus Klein 15 days ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF