Review main Merged

73260[FEATURE] Introduce unified and flexible templating for TYPO3 Backend

Christian Kuhn CR +2 V +2 Hard +574 −333 updated 02/03/22, 16:35

Commit message

This change introduces new functionality to revamp
the way the core works with views, especially in
backend context to finally achieve a 100% streamlined
templating and rendering concept for Backend output.

The change is based on the following cornerstones:

* ViewInterface (in "core" system extension)
  This is a new generic view interface that can be
  implemented by "view-aware" classes. It is *not*
  bound to fluid anymore, and could be used to connect
  any modern PHP template engine by building adapters.
  The interface brings definitions to add dynamic content
  to a view, plus a method to render the view.

* ResponsableViewInterface (in "core" system extension)
  This interface *can* be added in addition to the newly
  introduced ViewInterface. This is a shortcut interface
  to allow creating a PSR-7 Response object for simple
  cases directly, so controllers do not have
  to deal with ResponseFactory, as the "View" object
  creates the response, and not the controller anymore.

* FluidViewAdapter (in "core" system extension)
  This is a connector between the new ViewInterface
  and the Typo3Fluid implementation.
  This is only a loose connection from core to fluid,
  since that view is never used directly and only retrieved
  using a factory which can be exchanged using DI.

* BackendViewFactory (in "backend" system extension)
  A internal low level factory that returns an instance
  of the newly introduced ViewInterface - in the current
  status a FluidViewAdapter instance.
  On top, it configures default template paths and
  allows overriding them using TSconfig.

* ModuleTemplate
  This already existing class now implements both
  new interfaces ViewInterface and ResponsableInterface.
  This essentially makes the ModuleTemplate the view
  backend controllers can populate. The separation between
  "doc header" from ModuleTemplate and "body" with an
  own view is now obsolete.

The patch simplifies especially the way we deal with
backend module view renderings since ModuleTemplate is
now the view to operate on for actions. The former
ModuleTemplate HTML template is now a *layout*, which can
be used by backend module templates to take care of doc header.

As a bonus feature, layout / template / partial resolving can
be extended using TSconfig, which allows overriding *any* backend
template as soon as all backend views use this strategy.

The patch brings the main interfaces and a first ReST
explaining the feature. Further patches will change
backend views to use this strategy, will deprecate the
old way together with ReST files explaining code further
adaptions and will take care of some loose ends when
further related puzzle pieces fall in place.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Benni Mack +2
    • Oli Bartsch +1
    • Stefan Bürk +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Benni Mack +2
    • Oli Bartsch +1
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 1

Files 13

Review log 3342

Show 1317 earlier messages
  1. Christian Kuhn uploaded patch set 1 02/02/22, 13:35

  2. core-ci voted on patch set 1 V +1 02/02/22, 13:45 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22905

  3. Oliver Klee commented on patch set 1 02/02/22, 13:47

    phpstan-baseline.neon:2214

    This warning seems to indicate a problem. Maybe some type declaration is not correct yet?
  4. Christian Kuhn updated the commit message in patch set 2 02/02/22, 14:08

  5. Christian Kuhn commented on patch set 2 02/02/22, 14:10

    phpstan-baseline.neon:2214 Reply

    We have that in many more places already. Can no be resolved, needs a change in Typo3Fluid ... That issue is on my radar and I'll try to come up with something for Typo3Fluid later (probably an optional interface) to get rid of that later.
  6. Christian Kuhn commented on patch set 2 02/02/22, 14:13

    phpstan-baseline.neon:2214 Reply

    Point is: the TemplateView of fluid *is* template aware on render(), but the main Typo3Fluid interface does not reflect this ... to solve this, we'll add another interface in Typo3Fluid, most likely. When that is in place, we can adapt our usages. I also do NOT want to type hint TemplateView here, but ViewInterface.
  7. core-ci voted on patch set 2 V +1 02/02/22, 14:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22907

  8. Oliver Klee wrote 02/02/22, 15:08

    Removed cc Oliver Klee.
  9. Stefan Bürk updated the commit message in patch set 3 02/02/22, 18:30

  10. core-ci voted on patch set 3 V +1 02/02/22, 18:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22916

  11. Stefan Bürk commented on patch set 3 02/02/22, 19:37

    phpstan-baseline.neon:2214 Reply

    Fixing this in Typo3Fluid would be the better way instead of glutter core with possible superflous typehints to mitigate this. Fully following lolli's explanation and strategy on that point. I'm fine with this.

    BackendViewFactory.php:81

    Not sure - but before narrowing down template overrides to composer package name construct only, shouldn't we have the pre-requisit in core to enforce all extensions *must* have an composer.json ? https://review.typo3.org/c/Packages/TYPO3.CMS/+/73192
  12. Oli Bartsch commented on patch set 3 02/02/22, 22:19

    ModuleTemplate.php:116

    Same question as for the ViewInterface. Why do we duplicate the return type in the method name?

    ModuleTemplate.php:144

    While the module is rendered and assigned to the stream, the method still returns the Response object. Therefore, we should IMO just stick to the "createResponse" naming.

    BackendViewFactory.php:45

    Why do we allow null here? Will there be any use case where the factory is called, while having no Request available?

    BackendViewFactory.php:70

    Possible null pointer here.

    BackendViewFactory.php:72

    I currently don't fully get how the TSconfig might look like. Could we get some example here? Also I don't see the possibility to just override single paths, e.g. templateRootPaths. As soon as I configure this, Template, Layout and Partial paths are added even if they do not exist, right?

    BackendViewFactory.php:76

    This might lead to an undefined array key warning in case $override does not contain ":".

    FluidViewAdapter.php:34

    What's the benefit of this annotation?

    ViewInterface.php:40

    Why do we duplicate the return type in the method name?

    Feature-96730-SimplifiedExtbackendModuleTemplateAPI.rst:36

    Actually this method does not exist, $moduleTemplate->renderContent() is currently called in those controllers.
  13. Christian Kuhn commented on patch set 3 02/03/22, 09:03

    phpstan-baseline.neon:2214 Reply

    kk, so let's adapt Typo3Fluid here.

    ModuleTemplate.php:116 Reply

    naming things hard ;) renderString() and renderResponse() match well. your suggestion is render() (which is more-in-line with current fluid, too), plus createResponse() ...

    ModuleTemplate.php:144 Reply

    well. the emphasis is now on 'render': the view is rendered and a response is created from it. your suggestion is to put the emphasis on 'create'. unsure.

    BackendViewFactory.php:45 Reply

    Request is optional in view. It is no hard requirement to add this, it is allowed to not add a request. RenderingContext can deal with setRequest(null). For this backend context. Well yeah, it might be easier to simply enforce Request here.

    BackendViewFactory.php:70 Reply

    will be changed by making request non-optional.

    BackendViewFactory.php:72 Reply

    My wip has an example, usage will be documented in a .rst with the next patch: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73180/20/typo3/sysext/seo/Configuration/page.tsconfig And yes, all 3 parts are configured to be overriden: This does not hurt and is more convenient in the usage.

    BackendViewFactory.php:76 Reply

    true. will adapt.

    BackendViewFactory.php:81 Reply

    yes / no: A patch to enforce composer.json in pending by Benni already. With current state it's simply that you can't have overrides for a package that does not have composer.json.

    FluidViewAdapter.php:34 Reply

    don't know. we're using that in various places. can drop it.

    ViewInterface.php:40 Reply

    that's a bit matter of taste: It fits better to the pair method renderResponse().

    Feature-96730-SimplifiedExtbackendModuleTemplateAPI.rst:36 Reply

    true. will adapt.
  14. Christian Kuhn uploaded patch set 4 02/03/22, 09:21

  15. Christian Kuhn commented on patch set 4 02/03/22, 09:21

    ModuleTemplate.php:144 Reply

    changed renderString() to render() and renderResponse() to createResponse() now.
  16. core-ci voted on patch set 4 V +1 02/03/22, 09:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22937

  17. Stefan Bürk voted on patch set 4 V +1 CR +1 02/03/22, 11:49

  1. Christian Kuhn voted on patch set 4 CR -1 02/03/22, 12:17

  2. Christian Kuhn uploaded patch set 5 02/03/22, 12:58

  3. Christian Kuhn uploaded patch set 6 02/03/22, 13:00

  4. core-ci voted on patch set 5 V +1 02/03/22, 13:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22947

  5. core-ci voted on patch set 6 V +1 02/03/22, 13:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22948

  6. Benni Mack updated the commit message in patch set 7 02/03/22, 14:16

  7. Benni Mack voted on patch set 7 V +1 CR +1 02/03/22, 14:16

  8. Benni Mack updated the commit message in patch set 8 02/03/22, 14:17

  9. Christian Kuhn voted on patch set 8 V +1 CR +1 02/03/22, 14:18

  10. Stefan Bürk voted on patch set 8 V +1 CR +1 02/03/22, 14:30

  11. Benjamin Franzke commented on patch set 8 CR -1 02/03/22, 14:32

    Module.html:17

    bootstrap, ContextHelp, GlobalEventHandler, ActionDispatcher and ImmediateActionElement are not related to any HTML in this file (only DocumentHeader as far as I see) These "global" javascript modules should therefore rather be kept in the ModuleTemplate. Would also make the removal of the "($this->getBackendUserAuthentication() && !empty($this->getBackendUserAuthentication()->user)" more obvious for reviewers.
  12. core-ci voted on patch set 7 V +1 02/03/22, 14:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22950

  13. Benjamin Franzke commented on patch set 8 02/03/22, 14:38

    Feature-96730-SimplifiedExtbackendModuleTemplateAPI.rst:42

    packageName attribute missing
  14. Benjamin Franzke commented on patch set 8 02/03/22, 14:43

    Module.html:7

    Is there a reason why the legacy module template doesn't use the new Layout?
  15. Benjamin Franzke commented on patch set 8 02/03/22, 14:46

    Feature-96730-SimplifiedExtbackendModuleTemplateAPI.rst:18

    I didn't get what this sentence is saying. I'm not a language expert, but maybe: The default document header of :php:`ModuleTemplate` can be rendered using a new fluid layout named `Module`.
  16. Christian Kuhn uploaded patch set 9 02/03/22, 15:11

  17. Christian Kuhn commented on patch set 9 V +2 CR +2 02/03/22, 15:11

    Module.html:7 Reply

    yes. the old one is a template, the new one is a layout. we *could* merge that, but it's more dirty and needs special treatment. i thus decided to duplicate the template.

    Module.html:17 Reply

    i don't agree on that, but i'll put it back into moduleTemplate to get this patch merged and to not discuss this implementation detail now.

    Feature-96730-SimplifiedExtbackendModuleTemplateAPI.rst:18 Reply

    that's better. thx.

    Feature-96730-SimplifiedExtbackendModuleTemplateAPI.rst:42 Reply

    i left that out by intention since it will be obsoleted with one of the next patches. i also didn't wanted to elaborate on soon-obsolete stuff. i'll now put it in there again, we then have to remember to adapt it again.
  18. core-ci voted on patch set 9 V +1 02/03/22, 15:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22954

  19. core-ci voted on patch set 8 V +1 02/03/22, 15:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22951

  20. Christian Kuhn voted on patch set 9 V +1 CR +1 02/03/22, 15:29

  21. Oli Bartsch voted on patch set 9 V +1 CR +1 02/03/22, 15:55

  22. Stefan Bürk voted on patch set 9 V +1 CR +1 02/03/22, 16:08

  23. Benni Mack voted on patch set 9 V +2 CR +2 02/03/22, 16:30

  24. Christian Kuhn voted on patch set 9 V +2 CR +2 02/03/22, 16:31

  25. Christian Kuhn merged patch set 10 02/03/22, 16:35