Review main Abandoned

81547[FEATURE] Events to modify asset data in AssetRenderer

Simon Praetorius CR 0 V 0 Hard +558 −23 updated 09/11/24, 21:14

Commit message

The current implementation of `AssetRenderer` applies some
modifications to the supplied asset URIs before they are
rendered in the appropriate HTML tags. This patch adds two
new PSR-14 events which allows custom modifications to
Stylesheet or JavaScript tag attributes before rendering them.
The existing implementation of the Core is moved to an event
listener, which allows other events to skip the default
implementation and to replace it with a custom solution. For
that to work, the event implements `StoppableEventInterface`. In addition to the tag attributes,
the events have access to the supplied options of each asset
which allows for selective changes based on those options.
They also have access to the current request if available.

Both the basic functionality and the stoppable event are
covered by tests. To make this possible, the existing tests
for `AssetCollector` and `AssetRenderer` needed to be
refactored. While the test cases stay the same, the test
data is now part of each individual test class because
`AssetRendererTest` mostly needed to be changed to a
functional test. `AssetRendererExtensionTest` covers the
case where an extension wants to disable the Core's default
behavior altogether.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 13

Review log 3454

Show 1629 earlier messages
  1. Simon Praetorius uploaded patch set 1 10/25/23, 13:41

  2. core-ci voted on patch set 1 V -1 10/25/23, 13:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48165

  3. Simon Praetorius uploaded patch set 2 V -1 10/25/23, 14:04

  4. core-ci voted on patch set 2 V -1 10/25/23, 14:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48170

  5. Simon Praetorius uploaded patch set 3 V -1 10/25/23, 16:18

  6. core-ci voted on patch set 3 V -1 10/25/23, 16:26 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48185

  7. Simon Praetorius uploaded patch set 4 V -1 10/25/23, 17:26

  8. Simon Praetorius uploaded patch set 5 10/25/23, 17:27

  9. core-ci voted on patch set 4 V -1 10/25/23, 17:41 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48192

  10. core-ci voted on patch set 5 V -1 10/25/23, 17:42 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48193

  11. Simon Praetorius uploaded patch set 6 V -1 11/21/23, 18:56

  12. core-ci voted on patch set 6 V -1 11/21/23, 19:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49289

  13. Simon Praetorius abandoned the change 02/01/24, 09:27

    I discussed with benni that there should be a different approach here: Unify PageRenderer and AssetCollector, add Event chain to modify URIs
  14. Simon Praetorius restored the change 09/06/24, 14:22

  15. Simon Praetorius uploaded patch set 7 V -1 09/06/24, 14:24

  16. core-ci voted on patch set 7 V -1 09/06/24, 14:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64973

  17. Simon Praetorius uploaded patch set 8 V -1 09/06/24, 14:40

  18. core-ci voted on patch set 8 V -1 09/06/24, 14:52 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64977

  19. Simon Praetorius uploaded patch set 9 V -1 09/06/24, 15:37

  20. core-ci voted on patch set 9 V -1 09/06/24, 15:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64987

  21. Simon Praetorius uploaded patch set 10 V -1 09/06/24, 17:04

  22. core-ci voted on patch set 10 V -1 09/06/24, 17:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64993

  23. Simon Praetorius uploaded patch set 11 V -1 09/06/24, 17:12

  24. core-ci voted on patch set 11 V +1 09/06/24, 17:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64994

  25. Simon Praetorius uploaded patch set 12 V +1 09/07/24, 15:45

  26. core-ci voted on patch set 12 V -1 09/07/24, 15:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65019

  27. Simon Praetorius marked it ready for review 09/07/24, 16:35

  28. Simon Praetorius uploaded patch set 13 V -1 09/07/24, 16:36

  29. core-ci voted on patch set 13 V -1 09/07/24, 16:43 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65023

  1. Simon Praetorius uploaded patch set 14 V -1 09/07/24, 16:44

  2. core-ci voted on patch set 14 V +1 09/07/24, 16:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65024

  3. Stefan Bürk commented on patch set 14 CR -1 09/07/24, 19:57

    Unresolved

    We need to discuss some things regarding the events, and Benni asked to postpone this until monday/thusday - thus -1 temp for now.
  4. Garvin Hicking commented on patch set 14 09/07/24, 20:01

    I really like the idea of being able to adjust this with events, as frontend build integration gets more versatile (and complex). Not voting yet because of the implementation details of abstract events and/or pcpp

    AssetRenderer.php:71

    how about allowing the event to also suppress an asset?

    AssetRenderer.php:99

    Same here - also allow to suppress? And/or also allow to change the "rel" attribute?
  5. Garvin Hicking commented on patch set 14 09/07/24, 21:37

    Feature-102255-AddEventsToModifyAssetURIsInAssetCollector.rst:15

    one '\' missing after 'Event'
  6. Simon Praetorius uploaded patch set 15 CR -1 V +1 09/09/24, 09:20

  7. core-ci voted on patch set 15 V +1 09/09/24, 09:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65069

  8. Simon Praetorius uploaded patch set 16 V +1 09/09/24, 09:58

  9. Simon Praetorius commented on patch set 16 09/09/24, 09:59

    I've removed the abstract event and switched to CPP in the events.

    Feature-102255-AddEventsToModifyAssetURIsInAssetCollector.rst:15 Reply

    Done
  10. core-ci voted on patch set 16 V +1 09/09/24, 10:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65077

  11. Garvin Hicking commented on patch set 16 09/09/24, 10:21

    ModifyJavaScriptUriEvent.php:29

    `readonly` for the latter two?
  12. Simon Praetorius uploaded patch set 17 V +1 09/09/24, 10:38

  13. Simon Praetorius uploaded patch set 18 09/09/24, 10:39

  14. Simon Praetorius commented on patch set 18 09/09/24, 10:40

    ModifyJavaScriptUriEvent.php:29 Reply

    Done
  15. core-ci voted on patch set 17 V +1 09/09/24, 10:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65083

  16. core-ci voted on patch set 18 V +1 09/09/24, 10:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65084

  17. Benni Mack commented on patch set 18 09/11/24, 12:08

    AssetRenderer.php:73

    In addition, I think it would be quite helpful to also modify other attributes with this change, or what do you think? Same in the next one...
  18. Benni Mack commented on patch set 18 09/11/24, 12:11

    AssetRenderer.php:62

    let's extend this patch a bit further, but rendering the JavaScript AND actually handing this to the Event, should be important to add the PSR-7 request object
  19. Simon Praetorius uploaded patch set 19 V +1 09/11/24, 19:48

  20. Simon Praetorius uploaded patch set 20 09/11/24, 19:50

  21. Simon Praetorius commented on patch set 19 09/11/24, 19:53

    AssetRenderer.php:62 Reply

    Done

    AssetRenderer.php:71 Reply

    Do you have an idea for the api? Maybe set the attributes to null? Or empty array? Or something completely different?

    AssetRenderer.php:73 Reply

    Done

    AssetRenderer.php:99 Reply

    Done

    PageRenderer.php:1293 Unresolved

    I tried to go up the chain to provide the request in a "proper" way here. However I'm not sure about this `updateState()` construct of `PageRenderer`. Currently, the request doesn't seem to be available here.
  22. core-ci voted on patch set 20 V +1 09/11/24, 19:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65487

  23. core-ci voted on patch set 19 V -1 09/11/24, 19:58 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65486

  24. Garvin Hicking commented on patch set 20 09/11/24, 20:08

    AssetRenderer.php:71 Reply Unresolved

    I'd say that if get(Script|Link)TagAttributes() returns either an empty array or null, then the whole asset would be skipped?
  25. Simon Praetorius abandoned the change 09/11/24, 21:14