Review main Merged

81078[TASK] Have an event to modify constants AST in FE

Julian Mair CR +2 V +2 Easy +48 −0 updated 11/02/23, 15:00

Commit message

The new v12 TypoScript parser removed one undocumented
feature of the old parser in particular: Nested constants.

The core does not implement this anymore since it is
extremely hard to find a solution that scales well. The
problem becomes complicated with recursive usage
combined with values that may change at any point.

There are however a couple of instances that need this
feature and can't migrate away easily or at least not
without giving them a longer transition timeframe.

For this reason, the patch introduces an event in the
Frontend rendering chain that allows listeners to
manipulate the calculated constants AST structure.
This gives event listeners a chance to traverse the
calculated FE constants AST before it is cached and
further processed.

Implementing a resolver of nested constants should be
possible this way, even though extensions probably
restrict their implementation to limited scenarios.

This event is essentially a "last resort" solution: It
works in an environment where the AST is still marked
internal, and where the dispatching may still be
moved around to other places.

As such, this event is *not* marked as official feature.
It does not come with a ReST file, and it may change or
vanish in future major versions in case it becomes a
headache during further development. It is tailored for
developers who can't move away from nested constants and
need an intermediate solution right now.

Review

  • Code review CR +2 Done
    • Andreas Kienast +2
    • Christian Kuhn +1
  • Verified V +2 Done
    • Andreas Kienast +2
    • Julian Mair +1
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 1

Files 2

Review log 2431

Show 46 earlier messages
  1. Julian Mair uploaded patch set 1 09/19/23, 07:51

  2. Georg Ringer commented on patch set 1 09/19/23, 07:56

    this is clearly a feature but I would be fine to backport that to 12. however it needs a feature rst!
  3. core-ci voted on patch set 1 V +1 09/19/23, 08:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/46735

  4. Julian Mair uploaded patch set 2 V +1 09/19/23, 09:07

  5. Julian Mair commented on patch set 2 09/19/23, 09:08

    Reply

    done
  6. core-ci voted on patch set 2 V +1 09/19/23, 09:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/46744

  1. Christian Kuhn commented on patch set 2 CR -1 09/19/23, 14:59

    will review somewhere next days. we also may want to mark this event @internal or slightly move it around a bit.
  2. Benni Mack commented on patch set 2 09/19/23, 15:00

    I personally think this is the wrong spot to deal with flattened constants, as this would only affect TSFE / Frontend.
  3. Stefan Bürk commented on patch set 2 09/19/23, 16:29

    Feature-101752-IntroduceNewEventForAlteringTypoScriptConstants.rst:17

    We usually add a example event-listener implementation for a introduced event. Therefore, a example should be added here too. Beside this, the example can be used to verify this change and the new event.
  4. Stefan Bürk commented on patch set 2 09/19/23, 16:29

    Feature-101752-IntroduceNewEventForAlteringTypoScriptConstants.rst:17 Reply

    After deciding if the event is okay and in the right place.
  5. Julian Mair uploaded patch set 3 CR -1 V +1 09/21/23, 08:55

  6. Julian Mair commented on patch set 3 09/21/23, 09:00

    Reply

    Ack

    Reply

    your right, i didn't think that through ... in that case, I'm have no idea where the right spot for this event is

    Feature-101752-IntroduceNewEventForAlteringTypoScriptConstants.rst:17 Reply

    Done
  7. core-ci voted on patch set 3 V +1 09/21/23, 09:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/46989

  8. Jörg Bösche voted on patch set 3 CR +1 10/27/23, 07:30

  9. Chris Müller commented on patch set 3 10/27/23, 08:22

    Feature-101752-IntroduceNewEventForAlteringTypoScriptConstants.rst:48

    The event as argument is superfluous, as it is evaluated via reflection on compile time due to the type declaration. But the identifier is missing (although this is not required). I also suggest to move the attribute to the class level to be in line with all other changelogs.
  10. Christian Kuhn commented on patch set 3 CR -1 10/27/23, 17:15

    working on it.

    TypoScriptFrontendController.php:1158

    i think an event listener should work on the AST and not flatConstants.
  11. Christian Kuhn uploaded patch set 4 CR +1 V +1 10/27/23, 17:48

  12. Christian Kuhn commented on patch set 4 10/27/23, 17:49

    Feature-101752-IntroduceNewEventForAlteringTypoScriptConstants.rst:48 Reply

    i removed the ReST file. see commit message.

    TypoScriptFrontendController.php:1158 Reply

    Done
  13. Christian Kuhn updated the commit message in patch set 5 10/27/23, 17:52

  14. Christian Kuhn updated the commit message in patch set 6 10/27/23, 17:54

  15. core-ci voted on patch set 4 V -1 10/27/23, 17:58 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48306

  16. Christian Kuhn uploaded patch set 7 10/27/23, 18:01

  17. core-ci voted on patch set 6 V -1 10/27/23, 18:02 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48308

  18. core-ci voted on patch set 5 V -1 10/27/23, 18:03 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48307

  19. core-ci voted on patch set 7 V +1 10/27/23, 18:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48309

  20. Christian Kuhn commented on patch set 7 10/27/23, 18:23

    Note: this is still a bit fiddly. Event consumers now need to understand and change the AST. The proposed solution from earlier patches did hand over 'flat constants' instead, which I think is much more brittle, so I went with the AST instead. Additionally, 'flat constants' in not a cool construct, it's more a tribute to quick constant substitution lookups later, and I'm still thinking about different solutions for this. As such, I think the 'AST' solution is more stable mid-term, while the 'flat constants' solution uses an internal structure that may eventually vanish altogether.
  21. Julian Mair commented on patch set 7 V +1 10/30/23, 08:29

    Thanks, this solution works perfectly! However, I hope that this Event won't just quietly disappear in a bugfix version. Instead, we should have at least a few months or perhaps wait for a major Typo3 version to react and adapt to such changes.
  22. Christian Kuhn commented on patch set 7 V +1 CR +1 10/31/23, 15:16

    Hey. For the lifetime of this event: I'd estimate at the moment that this event won't just vanish at least in v13. Maybe internals of AST may change, but we'll see. Julian. In case you get something up and running regarding a 'nested constants' solution, it would be really if that could be documented somehow, for instance by adding a comment to the forge issue linking some code or repository or pasting the main code or something like that. This could help others looking for some solution. I'll vote this up now and will see if we can manage to get it merged.
  23. Julian Mair commented on patch set 7 11/02/23, 14:39

    Reply

    Regarding the lifetime: That sounds promising. And IMHO by adhering to Interfaces, we can potentially avoid significant breaking changes... As for documentation, I've uploaded an extension to GitHub and Packagist at https://packagist.org/packages/m41r/nested-typoscript-constants and noted the solution into the forge issue https://forge.typo3.org/issues/101752
  24. Andreas Kienast voted on patch set 7 V +2 CR +2 11/02/23, 15:00

  25. Andreas Kienast merged patch set 8 11/02/23, 15:00