[BUGFIX] Add constant evaluation in TypoScript functions
We missed a TypoScript feature with the new parser. Function operator modifier values can use constants: foo = 42 foo := addToList({$my.constant}) The solution is two fold: Until now, the value of a function body was a single T_VALUE token. This is turned into a stream of tokens that can consist of multiple T_VALUE and T_CONSTANT tokens. This is handled in the tokenizers. Secondly, the AST builders need to deal with these token streams now, and take care available constants are hand over to ConstantAwareTokenStream before the stream is cast to string and single functions are evaluated. The BE modules *do* reflect constant substitutions in function modifier bodies, but not in an ideal way. An @todo within the responsible CommentAwareAstBuilder outlines ideas how this could be improved. Note TYPO3 v13 supports constant fallbacks here as well, this syntax feature came with #103671. This works, but is NOT supported in v12: foo := addToList({$my.constant ?? $fallback.constant}) Resolves: #102742 Related: #97816 Related: #103671 Releases: main, 12.4 Change-Id: Ib5e0872fe1ea2b78bd0a7e05caccd9874b5668d4 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84498 Tested-by:core-ci <typo3@b13.com> Tested-by:
Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by:
Christian Kuhn <lolli@schwarzbu.ch>
Showing
- typo3/sysext/core/Classes/TypoScript/AST/AbstractAstBuilder.php 13 additions, 9 deletions...sysext/core/Classes/TypoScript/AST/AbstractAstBuilder.php
- typo3/sysext/core/Classes/TypoScript/AST/AstBuilder.php 1 addition, 1 deletiontypo3/sysext/core/Classes/TypoScript/AST/AstBuilder.php
- typo3/sysext/core/Classes/TypoScript/AST/CommentAwareAstBuilder.php 15 additions, 3 deletions...xt/core/Classes/TypoScript/AST/CommentAwareAstBuilder.php
- typo3/sysext/core/Classes/TypoScript/AST/Event/EvaluateModifierFunctionEvent.php 3 additions, 2 deletions...es/TypoScript/AST/Event/EvaluateModifierFunctionEvent.php
- typo3/sysext/core/Classes/TypoScript/Tokenizer/Line/IdentifierFunctionLine.php 9 additions, 8 deletions...sses/TypoScript/Tokenizer/Line/IdentifierFunctionLine.php
- typo3/sysext/core/Classes/TypoScript/Tokenizer/LosslessTokenizer.php 17 additions, 19 deletions...t/core/Classes/TypoScript/Tokenizer/LosslessTokenizer.php
- typo3/sysext/core/Classes/TypoScript/Tokenizer/LossyTokenizer.php 10 additions, 11 deletions...sext/core/Classes/TypoScript/Tokenizer/LossyTokenizer.php
- typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_typoscript_ast_function_event/Classes/EventListener/TyposcriptTestFunction.php 1 addition, 1 deletion...on_event/Classes/EventListener/TyposcriptTestFunction.php
- typo3/sysext/core/Tests/Unit/TypoScript/AST/AstBuilderInterfaceTest.php 139 additions, 0 deletions...ore/Tests/Unit/TypoScript/AST/AstBuilderInterfaceTest.php
- typo3/sysext/core/Tests/Unit/TypoScript/Tokenizer/Line/IdentifierFunctionLineTest.php 4 additions, 4 deletions.../TypoScript/Tokenizer/Line/IdentifierFunctionLineTest.php
- typo3/sysext/core/Tests/Unit/TypoScript/Tokenizer/TokenizerInterfaceTest.php 113 additions, 20 deletions...ests/Unit/TypoScript/Tokenizer/TokenizerInterfaceTest.php
Please register or sign in to comment