Review main Abandoned

81497[TASK] Extract ImageViewHelper logic into abstract class

Nikita Hovratov CR 0 V 0 Hard +368 −213 updated 10/21/24, 10:19

Commit message

To better reuse the image processing logic inside
ImageViewHelper, the main parts are extracted into a new trait
`ImageProcessingTrait`. This trait is then used in two new abstract
classes: AbstractImageViewHelper and AbstractTagBasedImageViewHelper.
While the trait holds the logic, the abstract classes define common
arguments and exception handling.

The result is slim ImageViewHelpers, which can be easily copied
for custom implementations.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 6

Review log 4051

Show 2026 earlier messages
  1. Nikita Hovratov uploaded patch set 1 10/21/23, 12:08

  2. Nikita Hovratov rebased onto patch set 2 10/21/23, 12:09

  3. core-ci voted on patch set 1 V -1 10/21/23, 12:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48001

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

  5. Nikita Hovratov uploaded patch set 3 V -1 10/21/23, 12:44

  6. core-ci voted on patch set 3 V +1 10/21/23, 12:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48004

  7. Nikita Hovratov uploaded patch set 4 V +1 10/21/23, 21:08

  8. core-ci voted on patch set 4 V +1 10/21/23, 21:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48016

  9. Garvin Hicking commented on patch set 4 10/25/23, 09:47

    (This is great. The ImageVH is my major gripe with "final" ViewHelpers, having an abstract for this soooo useful for agencies and extension developers who want some kind of "contract" with the core's image viewhelper when we extend it.)
  10. Nikita Hovratov uploaded patch set 5 V +1 10/27/23, 16:09

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

  12. Nikita Hovratov rebased onto patch set 6 V +1 11/16/23, 09:43

  13. core-ci voted on patch set 6 V +1 11/16/23, 09:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49007

  14. Oliver Klee commented on patch set 6 11/17/23, 11:01

    ImageProcessingTrait.php:26

    Should we add a `@mixin` annotation with the VH superclass or interface to make this even more explicit (and also PHPStan-recognizable)?

    ImageProcessingTrait.php:44

    Do we need null coalescing operators for any of the arguments accesses?
  15. Nikita Hovratov commented on patch set 6 11/17/23, 11:15

    ImageProcessingTrait.php:26 Reply

    Do we have an example for @mixin? I've never used it before.

    ImageProcessingTrait.php:44 Reply

    Arguments of VH are always set. If this is used outside of VH this would be necessary.
  16. Oliver Klee commented on patch set 6 11/17/23, 11:46

    ImageProcessingTrait.php:26 Reply

    Yes, sure: https://github.com/oliverklee/ext-feuserextrafields/blob/main/Classes/Domain/Model/CreationDateTrait.php The `@mixin` annotation basically says something along the lines of "This trait should only be used in this class (or subclasses) for the trait to make sense."

    ImageProcessingTrait.php:44 Reply

    Ack
  17. Nikita Hovratov commented on patch set 6 11/17/23, 16:08

    ImageProcessingTrait.php:26 Reply

    The only documentation I can find is this: https://phpstan.org/writing-php-code/phpdocs-basics#mixins There it describes it the other way around. The consuming class declares `@mixin` and not the "mixing" itself. Where do you have this information with traits from?
  18. Oliver Klee commented on patch set 6 11/17/23, 16:27

    ImageProcessingTrait.php:26 Reply

    I've also searched a bit and learned that the `@mixin` annotation indeed is not traits-specific. Instead, it communications that the class (or trait) that has the annotation has the properties/methods of the referenced class. In practice, this allows tools to make sense of property and method accesses in the trait. (I have no idea whether this was intended, but is works fine in my cases.) These two pages look helpful to me: https://freek.dev/1482-the-mixin-php-docblock https://psalm.dev/docs/annotating_code/supported_annotations/#mixins (which contains similar things to the PHPStan page) I also don't know if there is any better tool-readable way to communicate that "this trait is intended to be used with those classes". I'm open to learn more about this!
  19. Nikita Hovratov commented on patch set 6 11/18/23, 16:10

    ImageProcessingTrait.php:26 Reply

    Thanks for the further reading links! So, if I understand it correctly, adding `@mixin` to this trait won't have any benefits, because it consists of only static methods with no references to outside class method calls. The best way to communicate the intended usage is thus through comments, I believe. I mean, it could also be used in other contexts, but this would require some more refactoring of the `arguments` array. For now it should suffice to be used in ViewHelpers.
  20. Oliver Klee commented on patch set 6 11/18/23, 21:38

    ImageProcessingTrait.php:26 Reply

    Ack - then let’s keep the code as is. Thanks for bouncing these ideas around with me!
  21. Nikita Hovratov abandoned the change 02/18/24, 15:57

    No real feedback on this one, can be revived if needed.
  22. Simon Schaufelberger commented on patch set 6 02/18/24, 16:58

    @nikita.h@live.de I would have loved to see this patch as I have some Viewhelpers who extend the ImageViewHelper and it would be helpful to make use of the trait.
  23. Nikita Hovratov commented on patch set 6 02/19/24, 07:12

    Reply

    @simonschaufi+typo3@gmail.com If you want, you can adopt this patch. I just don't have time to invest in this right now. Ping me and I revive the patch. There was also a merge conflict to solve.
  24. Garvin Hicking commented on patch set 6 02/19/24, 07:59

    Oh, I'd also love to see if this could get implemented. I could happily rebase it to resolve conflicts. I have that SVG thing outstanding, which I hope can be adressed with core maintainers at the community sprint. If we can gauge interest, I hope we can resolve this patch herr and either get it done or officialled killed 😅
  25. Nikita Hovratov restored the change 02/19/24, 09:47

  26. Garvin Hicking uploaded patch set 7 V +1 02/19/24, 09:47

    Try to address merge conflicts WIP
  1. core-ci voted on patch set 7 V -1 02/19/24, 09:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53333

  2. Garvin Hicking uploaded patch set 8 V -1 02/19/24, 10:58

    CGL
  3. core-ci voted on patch set 8 V -1 02/19/24, 11:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53337

  4. Garvin Hicking commented on patch set 8 02/19/24, 11:14

    Note to self: I couldn't backport the "getExceptionMessage" change with the refactoring easily due to differences in static/non-static calls. This needs unification. (That method needs the rendering context and uses is from the $this-> context, so it can't really be called statically but would need passing of it via parameter (something like the getCustomExceptionMessage)) Need some time to check on this, if no one else does before me ;)
  5. Simon Schaufelberger uploaded patch set 9 V -1 05/15/24, 22:28

  6. Simon Schaufelberger commented on patch set 9 05/15/24, 22:28

    Reply

    Done
  7. core-ci voted on patch set 9 V +1 05/15/24, 22:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/57794

  8. Simon Schaufelberger uploaded patch set 10 V +1 05/15/24, 22:33

  9. core-ci voted on patch set 10 V +1 05/15/24, 22:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/57795

  10. Simon Schaufelberger voted on patch set 10 CR +1 V +1 05/15/24, 23:59

  11. Garvin Hicking commented on patch set 10 CR +1 V +1 05/16/24, 06:45

    Thank you Simon for adressing the merge conflict, I totally forgot about it. Applied it and it seems to work for me in the cases I've tested. I'm unsure though whether to backport this to v12. The image processing has changed so much in main that I think it will be both hard and potentially buggy to backport this to v12. I'd rather drop this from being backported and count as a hidden feature for v13 adoption? :-)
  12. Nikita Hovratov updated the commit message in patch set 11 CR +1 V +1 05/16/24, 07:23

  13. Nikita Hovratov commented on patch set 11 05/16/24, 07:23

    Reply

    I'd also say let's only keep for main. It can't be easily backported anyway. If it were merged half year ago this would have been another story.
  14. core-ci voted on patch set 11 V +1 05/16/24, 07:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/57823

  15. Christian Kuhn commented on patch set 11 CR -1 05/16/24, 07:35

    let's have a chat on this somewhere next days please, Nikita.
  16. Simon Schaufelberger commented on patch set 11 05/16/24, 07:46

    Reply

    sure, no problem. the release line can easily be adjusted 😊
  17. Simon Schaufelberger commented on patch set 11 05/16/24, 07:46

    Reply

    Done
  18. Simon Schaufelberger voted on patch set 11 CR +1 V +1 05/16/24, 07:47

  19. Garvin Hicking commented on patch set 11 06/13/24, 11:56

    Unresolved

    Since I just stumbled on this again on a project where I may need to fork the image viewhelper - is there a chance this patch might make it into v13? :-)
  20. Nikita Hovratov commented on patch set 11 06/17/24, 14:20

    Reply Unresolved

    Hey lolli, could you comment maybe here what you think about this patch? I think others could also help here (Simon, Garvin).
  21. Oliver Klee wrote 08/25/24, 10:11

    Removed cc Oliver Klee.
  22. Garvin Hicking commented on patch set 11 09/03/24, 19:52

    I had some thoughts when discussing this with Simon Praetorius. I think with the recent fluid efforts we should try to step away from traits and abstracts here. Maybe we could move the "factory-ish" parts (assigning/evaluating common arguments, input validation) into a proper factory service, let it wire arguments to VHs, and then have the logic (handling resources/files, preparing conversions etc) in its own service (or maybe even i imageService). IMO we should strife to make VHs leaner and less based on abstracts/traits, to allow composition, and that would make custom VH implementations be able to utilize the same services. This way we can fulfill the reasoning behind final non-api ViewHelpers, and also make service-based testing easier...?
  23. Christian Kuhn commented on patch set 11 10/21/24, 09:12

    Reply

    Hey. I have similar feelings. These are my reasons I don't like the proposed abstraction much: * First, it's not really much code. The main ImageVH is mainly sanitation code plus glue code that connects other services and adds a little bit of handling specific for this use case, the latter part are the areas where the different VH flavors are different. Abstracting glue code away does not give us much and creates some API methods that are hard to maintain and will probably see constant "we had to deprecate this or that detail" patches. * The ImageVH shrinks over time. The list of arguments for instance nearly halfed between v12 and v13 due to better general fluid handling. * Hard coding the default arguments in the abstract creates a "flavored" / "opinionated" abstract that is hard to change if you'd like to get rid of some of the arguments in a custom implementation. * All in all, the patch proposes two abstracts plus one trait. All that smells kinda overkill to me for the amount of code. * We could simplify the code a bit more: The fact that we deal with 3 different exceptions (and two of them global exceptions!) is a bug in FAL - this should be streamlined in FAL, and we should probably catch only one intermediate FAL exception here. Getting FAL right in this area would then drop the need for getExceptionMessage(), and would boil down to only one 'catch', probably. All in all, we're really not talking about *that* much code here, and the proposed solutions shows that "abstracting" this away leads to quite a bit of additinional complexity instead of a simplification. As such, I rather tend to not do such a change at all, but to have a look which existing details in the underlying services could be simplified a bit more to be more easy to use. What do you think?
  24. Christian Kuhn commented on patch set 11 10/21/24, 10:19

    Reply

    recheck with nikita: he is fine with abandoning this approach.
  25. Christian Kuhn abandoned the change 10/21/24, 10:19