Closed (fixed)
Project:
Svg Image
Version:
3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
10 Jan 2022 at 10:30 UTC
Updated:
4 Dec 2024 at 20:22 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mrshowermanHere's a first patch.
Comment #3
mrshowermanMake sure the #item_attributes is always an array.
Comment #4
nironan commentedComment #6
nironan commentedRebased against 3.x, here is the diff: https://git.drupalcode.org/project/svg_image/-/merge_requests/18.diff
Comment #7
prashant.cThere is an issue:
svg_image_responsive/src/Plugin/Field/FieldFormatter/SvgResponsiveImageFormatter.php$linkFile in isset() is never definedComment #8
mrshowermanAdressing #7
Comment #9
mrshowermanComment #10
grevil commentedPointing out @mably's comment here, as some people don't get mail notifications through gitlab:
Comment #11
mrshowermanRe-rolled.
Comment #12
mrshowermanNow all tests are green.
Comment #13
mably commented@mrshowerman thanks for the rebase.
The suggested improvement seems to executes some code twice like;
which gets executed in the parent first and then is executed a second time in the child formatter.
So I'm not sure the gain is really worth it.
Let's see what others think about it.
Comment #14
gaëlgThis code is executed twice because it looks like we need $images in the overriding method, to loop on it. It seems there's no clean way to do otherwise without re-implementing the parent method. Ideally, the parent method might be split into several ones so that we don't have to make that second call, but from a contrib module point of view, we can't change core code.
Yes, this is not perfect because it could have a negative impact on performance.
BUT performance is not the only criteria. I this case, I suspect the second call will be very fast and lead to no additional SQL query thanks to various Drupal cache layers. Additionally, the result of this execution can also be cached (render caching).
So I'd say we can trade a tiny performance degradation to get a contrib module that has much more chance to work well with subsequent core versions.
Comment #15
mirakolous commentedSharing in case anyone else runs into this. The current patch is behind and does not apply. I attempted to rebase, but it was too many conflicts for me to resolve confidently. In order to not stall the updates to other modules, I had to change svg_image in composer.json like so:
"drupal/svg_image": "dev-3.x#2fe16c7a9f0c511bbcaa44499a4fb61fa0f9854c",
That is the last hash that this patch applies cleanly to.
Comment #16
gaëlg@mirakolous The patch generated from the MR (https://git.drupalcode.org/project/svg_image/-/merge_requests/18.diff) applied on 3.0.1 some days ago.
Comment #17
mrshowermanRebased the MR onto the latest 3.x.
@mirakolous, you should now be able to apply the MR's plain diff to 3.x-dev again.
Comment #18
sagesolutions commentedI could not apply the MR #18 diff to any logical branch. I tried version 3.0.2, version 3.1.0, dev-3.x#2fe16c7a9f0c511bbcaa44499a4fb61fa0f9854c, and the latest 3.x-dev branch.
Patching all of them failed.
Comment #19
mrshowermanRebased.
@sagesolutions, you should be able to test this now against 3.x-dev.
Comment #20
sagesolutions commentedTested on the 3.x-dev branch and Image loading attributes are now working properly. Thanks @mrshowerman!
Comment #21
grevil commentedChanges LGTM! Could you add a few explanatory comments in the code?
Some of the code is not straight forward. Adding comments would speed up understanding the code in the future! 🙂
Comment #22
mrshowermanAll feedback has been addressed, except for one thing where @mably requests input from @Grevil. Setting back to NR.
Comment #23
grevil commentedResolved most threads, but one! Then we can merge this :)
Comment #24
mrshowermanAddressed feedback by @grevil.
Comment #26
mably commentedMerged! Thanks for all the great work.
Comment #27
mably commentedComment #28
grevil commentedIs there an open issue for this already? What are the steps to reproduce this?
Comment #29
mrshowermanNot yet. I had a quick look at this yesterday and was able to reproduce. I also have a fix ready.
Will create a new issue with that fix soon.
Comment #30
mrshowerman@mably, I will also have a look into #3477774: Use a trait to reduce code duplication in formatters.
Comment #31
mably commentedThanks @mrshowerman !
Comment #32
mably commentedThe problem is that ImageFormatter and Responsive ImageFormatter render the link differently:
image-formatter.html.twig:responsive-image-formatter.html.twig:So we just need to also override the
#urlproperty when we override the#themeproperty toimage_formatterin theSvgResponsiveImageFormatterclass.Comment #33
mably commented@mrshowerman not sure we need to create a new issue for that, just open a new MR here with the fix.
Comment #34
grevil commentedI agree with @mably. I originally thought, that the problem was unrelated based on:
Fine if we create a follow-up fix here!
Comment #35
mably commentedYep, removed that comment in Gitlab as it is working with 3.1.0 in fact.
Should be an easy fix.
Comment #36
mrshowermanOops, missed that. I created #3486745: Fatal error when linking SVGs to file in the meantime, but I'll be happy to add the fix to this issue if that is preferred.
Comment #38
mrshowermanCreated a new MR that addresses all open issues.
Not sure what the right status should be now 🙈
Comment #42
mably commentedMerged. Thanks for the quick fix @mrshowerman!
Comment #43
grevil commentedGreat stuff! Thanks all! :)
I guess, we should create a new release pretty soon! Let's wait a couple of days, just in case we find anything else.
Comment #45
nkind commentedJust wondering if there's an ETA for the next release with this since it includes the image attribute fix as well?
Great work to all involved by the way!
Comment #46
mably commented@nkind version 3.2.0 including this fix has been released!
Comment #47
nkind commented@mably Thank you!