Project

General

Profile

Actions

Bug #102742

open

TypoScript constants not usable in value modification addToList()

Added by Karsten Nowak (undkonsorten) 4 months ago. Updated about 2 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2024-01-03
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

clipboard-202401031121-wvn5c.png (8.96 KB) clipboard-202401031121-wvn5c.png Karsten Nowak (undkonsorten), 2024-01-03 10:21

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #97816: New TypoScript parserClosed2022-06-27

Actions
Actions #1

Updated by Christian Kuhn 4 months ago

Actions #2

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.

Actions #3

Updated by Garvin Hicking 3 months ago

(Will work on this, if someone else wants in too, let me know on Slack or here)

Actions #4

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

Actions #5

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

Actions #6

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

Actions #7

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

Actions #8

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

Actions #9

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

Actions #10

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

Actions #11

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

Actions #12

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

Actions #13

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

Actions

Also available in: Atom PDF