Review main Merged

72027[BUGFIX] Ensure form finisher dependencies can get injected

Elias Häußler CR +2 V +2 Easy +23 −8 updated 11/05/21, 05:35

Commit message

With #94317 the instantiation of form finishers has been changed by
replacing `ObjectManager::get()` in favor of
`GeneralUtility::makeInstance()`. However, since form finishers are
not public by default it was impossible to inject required
dependencies into it.

This patch ensures dependencies of form finishers can
be injected by making them available through the symfony dependency
injection container.

As finishers contain state (setOptions()), they are marked as not
shared.

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Nikita Hovratov +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Chris Müller +1
    • Nikita Hovratov +1
    • core-ci +1 CI

Issues 3

Files 2

Review log 2428

Show 23 earlier messages
  1. Elias Häußler uploaded patch set 1 11/02/21, 18:26

  2. Elias Häußler wrote 11/02/21, 18:46

    Topic set to di
  3. core-ci voted on patch set 1 V +1 11/02/21, 18:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/18766

  1. Chris Müller voted on patch set 1 V +1 11/02/21, 18:57

  2. Mathias Brodala commented on patch set 1 CR -1 11/03/21, 07:44

    Why not do this in the existing Services.yaml instead?
  3. Elias Häußler commented on patch set 1 11/03/21, 08:00

    Reply

    The mentioned switch from `OM::get` to `GU::mI` resulted in existing form finishers no longer getting dependencies injected unless they are public. IMHO this is a breaking change since prior to the change, dependencies were always injected (by the ObjectManager) which is no longer the case (as they not public by default). We could indeed set only the core finishers to "public", but this would not cover finishers from third-party extensions, because prior to mentioned change there was no need to set them public – if I understand it correctly. If we decide to NOT make form finishers public by default, I think we should at least provide an important rst that documents mentioned change and the need for public form finishers for DI.
  4. Mathias Brodala commented on patch set 1 CR 0 11/03/21, 08:21

    Reply

    I indeed missed that you make ALL finishers public by their interface. But technically this should also be doable in the Services.yaml AFAIK.
  5. Elias Häußler commented on patch set 1 11/03/21, 08:26

    Reply

    You mean services: _instanceof: TYPO3\CMS\Form\Domain\Finishers\FinisherInterface: public: true ?
  6. Mathias Brodala commented on patch set 1 11/03/21, 08:32

  7. Elias Häußler commented on patch set 1 11/03/21, 08:44

    Reply

    I already took this into consideration, but decided against it in oder to streamline this implementation with the ones from other system extensions. But it would also okay for me to change it as described.
  8. Mathias Brodala commented on patch set 1 11/03/21, 08:46

    Reply

    Indeed, there are other uses of the PublicServicePass configured via Services.php instead of Services.yaml. So I guess that's fine for now.
  9. Benjamin Franzke commented on patch set 1 CR -1 11/03/21, 09:07

    I agree that #94317 isn't a proper change (it should have checked whether a container entry exists and use PSR-11 container->get() in that case and fallback to ObjectManager->get() together with a deprecation log). Now, it's generally nice to autoconfigure ervices, but that also has a slight drawback: a) Extensions may not have enable Service autoconfiguration b) Finishers may be stateful I'm undecided whether we rather fix #94317 to fallback to ObjectManager, but in any case, if we would want to merge this, then we'd also need to (auto)configure the finishers to be statefull (`shared = false`). We could add that as option to `PublicServicePass`

    Reply

    FYI: _instanceof: via Services.yaml would only apply for the current extension, not all extensions. This kind of global autoconfiguration requires a compiler pass.
  10. Benjamin Franzke commented on patch set 1 11/03/21, 09:09

    Reply

    Note: The finishers need to be considered statefull because the Interface implicitly mandates state due to the `setOption[s]()` methods.
  11. Benjamin Franzke uploaded patch set 2 11/03/21, 09:18

  12. Benjamin Franzke uploaded patch set 3 11/03/21, 09:19

  13. Elias Häußler commented on patch set 3 11/03/21, 09:25

    Reply

    Nice catch, thanks! I always forget that public: true implicitly sets shared: true as well...
  14. core-ci voted on patch set 2 V +1 11/03/21, 09:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/18773

  15. core-ci voted on patch set 3 V +1 11/03/21, 09:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/18774

  16. Benjamin Franzke voted on patch set 3 CR +1 11/03/21, 09:58

  17. Chris Müller voted on patch set 3 V +1 11/03/21, 19:35

  18. Nikita Hovratov updated the commit message in patch set 4 11/04/21, 16:05

  19. Nikita Hovratov commented on patch set 3 V +1 CR +1 11/04/21, 16:06

    Only commit message adjustments.
  20. core-ci voted on patch set 4 V +1 11/04/21, 16:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/18907

  21. Benjamin Franzke voted on patch set 4 V +1 CR +1 11/04/21, 17:01

  22. Nikita Hovratov voted on patch set 4 V +1 CR +1 11/04/21, 17:12

  23. Chris Müller voted on patch set 4 V +1 11/04/21, 18:01

  24. Benjamin Franzke commented on patch set 4 V +2 CR +2 11/05/21, 05:35

    Reply

    Done
  25. Benjamin Franzke merged patch set 5 11/05/21, 05:35