Bug #102742
openTypoScript constants not usable in value modification addToList()
0%
Description
If we use constants in value modifications like addToList()
(maybe others too) they are not replaced with the value of the constants. Used constants are not nested constants!
Example:
# TypoScript Constants
test.foo = bar
# TypoScript Setup
page.1 = TEXT
page.1 {
value = Test1
value := addToList({$test.foo})
}
page.2 = TEXT
page.2 {
value = Test2
value := addToList(one,two)
wrap = <br />|
}
Expected output should be
Test1,bar
Test2,one,two
but is
Test1,{$test.foo}
Test2,one,two
In "Active TypoScript" with activated checkbox "Substitute constants in setup" it is also not replaced.
Environment: TYPO3 12.4.9 and PHP 8.2.4
Files
Updated by Christian Kuhn 4 months ago
- Related to Feature #97816: New TypoScript parser added
Updated by Christian Kuhn 3 months ago ยท Edited
Confirmed. This is not parsed. Not even tokenized. I guess we completely missed this since it was never documented function body values could be constants.
This seems to be a rather seldom used feature though, otherwise we'd have seen more people complaining about this already.
Here is what has to happen:
LossyTokenizer and LosslessTokenizer need to parse the 'token body' to create a T_VALUE & T_CONSTANT stream instead of just a singe T_VALUE. The key change is to mess around with $this->currentLineString and trigger parseValueForConstants() for the body. This needs to be done carefully, especially in LossLessTokenizer. IdentifierFunctionLine has to be changed to carry this stream instead of a single value. The tokenizer needs to create either a ConstantAwareTokenStream when there is a constant in there, or a TokenStream (this is pretty clever since creating special objects during tokenizing already if a constant is involved prevents ast builder (which is done more often than tokenizing due to cache layers) from scannig for constants often). Additional unit tests should verify this works. The code involved isn't trivial, but a change should be do-able, the LossyTokenizer will be more easy to handle than the LosslessTokenizer. There is existing code in the two tokenizers that do similar things already.
And I think that's basically it, constant substitution then should probably auto kick in within AST-builder I guess, but it's possible it needs a minor change to be aware of streams instead of a single token only. An AST builder test will find out details. We may need to stringify such ConstantAwareTokenStream relatively early within the AST builder to resolve T_CONSTANT to the final value, otherwise a chain like addToList(${my.constant}) (which is resolved to say "42") and then another call with removeFromList(42) wouldn't work. Tests should verify this is fine.
Updated by Garvin Hicking 3 months ago
(Will work on this, if someone else wants in too, let me know on Slack or here)
Updated by Gerrit Code Review 3 months ago
- Status changed from New to Under Review
Patch set 8 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review 3 months ago
Patch set 9 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review 3 months ago
Patch set 10 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review 3 months ago
Patch set 11 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review 3 months ago
Patch set 12 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review 2 months ago
Patch set 13 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review about 2 months ago
Patch set 14 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review about 2 months ago
Patch set 15 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review about 2 months ago
Patch set 16 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review about 2 months ago
Patch set 17 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633
Updated by Gerrit Code Review about 8 hours ago
Patch set 18 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/82633