Bug #102742
closedTypoScript constants not usable in value modification addToList()
100%
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 11 months ago
- Related to Feature #97816: New TypoScript parser added
Updated by Christian Kuhn 10 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 10 months ago
(Will work on this, if someone else wants in too, let me know on Slack or here)
Updated by Gerrit Code Review 10 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 9 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 9 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 9 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 9 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 9 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 9 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 9 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 9 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 9 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 7 months 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
Updated by Gerrit Code Review 6 months ago
Patch set 19 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 6 months ago
Patch set 20 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 Christian Kuhn 6 months ago
- Related to Task #103944: Update less class state in TypoScript tokenizers added
Updated by Gerrit Code Review 6 months ago
Patch set 21 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 6 months ago
Patch set 22 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 6 months ago
Patch set 23 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 6 months ago
Patch set 24 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 6 months ago
Patch set 25 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 6 months ago
Patch set 26 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 6 months ago
Patch set 27 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 6 months ago
Patch set 28 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 6 months ago
Patch set 29 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 6 months ago
Patch set 30 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 6 months ago
Patch set 31 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 6 months ago
Patch set 32 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 6 months ago
Patch set 33 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 6 months ago
Patch set 34 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 Christian Kuhn 6 months ago
a constant:
project = TYPO3v12
a usage:
page.40 = TEXT page.40.value = foo page.40.value := addToList({$project})
BE display: see screenshot
Updated by Christian Kuhn 6 months ago
- Related to Feature #103671: Provide null coalesce operator for TypoScript constants added
Updated by Gerrit Code Review 6 months ago
Patch set 35 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 6 months ago
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84498
Updated by Christian Kuhn 6 months ago
This took a while, but it's now done and will be available with next v12 patch level.
Updated by Garvin Hicking 6 months ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 89816343b67777a0aa4df73e8a1670355876d7b5.
Updated by Christian Kuhn 6 months ago
- Related to Task #103982: Require array in setFlatConstants() added