Problem/Motivation
ImageStyle::flush allows to delete a particular image in an image style, However the hook invoked from the flush() method doesn't pass this path value.
Proposed resolution
Pass $path along to the hook and make sure the hook is invoked when a path is passed.
Remaining tasks
None
User interface changes
None
API changes
$path is passed to hook_image_style_flush
hook_image_style_flush is invoked when a $path is passed
Release note
hook_image_style_flush is now invoked if ImageStyle::flush is called with the $path parameter set. Previously the hook was only called if no path was passed to this method. Also, the path parameter is now passed along to the hook implementation.
Comments
Comment #5
firewaller commentedThis happens partially because the hooks are not invoked when $path is set in Drupal\image\Entity\ImageStyle::flush():
The attached patch triggers things appropriately. The next step is to add $path as an additional argument for the hook.
Comment #6
firewaller commentedAttached is an updated patch that passes $path as an additional argument for the hook.
Comment #7
borisson_This looks like it's an API break? There isn't anything on the BC policy page about alter hook arguments, so I'm not sure.
Comment #9
psebborn commentedRe-rolled the patch from #6 as it didn't apply cleanly for me (8.7.3)
Comment #10
mr.baileysComment #11
berdirthere must be no empty line betwen the params and the param needs to document the type.
I think BC is OK, the only theoretical scenario is that someone would call the hook from a different place and not pass the second argument. We can fix that by documenting it as optional and defaulting to NULL.
Comment #12
mr.baileysComment #13
ravi.shankar commentedI have re-rolled the patch against Drupal 8.9.x-dev and made changes that mentioned in #11.
Comment #17
idebr commentedAttached patch implements the following changes:
Comment #18
idebr commentedComment #21
weseze commentedJust confirming that the patch from #17 still works perfectly fine against D9.4.7
Comment #22
WagnerMelo commentedHi, i'll review it.
Comment #24
vistree commentedJust to confirm: the patch from #17 still applies to Drupal core 9.4.9. I also needed this patch to get https://www.drupal.org/project/imageapi_optimize_webp/issues/3213379 working (WebP image styles not being updated using focal_point module)
Comment #25
martijn de witDoes this solution needs a test, and so a status Needs work? Or can we RTBC this?
I see many +1 in the #3213379: WebP images are not regenerated when using image_widget_crop ticket.
Comment #26
elberHi can you add steps to reproduce this issue ? Please.
Comment #27
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Think this could use a test case to show the issue.
Also since a new parameter is being added to the hook it will need a change record
thanks
Comment #29
lendudeAdded a test. Adding a test-only for $path being passed is non-sensical since we wouldn't expect that to pass currently, but we can test the change where if you pass a $path to flush(), currently the hook is never called at all.
So added a test for that.
Test only is the interdiff.
Comment #31
borisson_Test coverage looks solid.
Comment #32
idebr commentedComment #33
lendudeAdded an attempt at a CR, https://www.drupal.org/node/3373248
Comment #34
lauriiiWould be great to get confirmation from the release managers that the behavior change here is acceptable for a minor release.
Comment #35
catchI think this is sensible for a minor release - more likely it fixes a bug for someone than breaks it, and easy mitigation if there's a problem.
Comment #36
lendudeUpdated the IS, added a release note
Comment #38
mr.baileysTest failure was unrelated to this change, and tests are back to green, so reverting to RTBC.
Comment #39
alexpottThese seems a surprising change for me. Currently the hook is only invoked when a whole style is being flushed and not a single path. Therefore all existing implementations are going to assume that the everything is being flushed and not just a single path and therefore act accordingly. That said I can only find 2 instances of this hook in contrib and one already requires this patch so I think I agree with @catch here - okay for a minor release.
Committed 996fb53 and pushed to 11.x. Thanks!
Did a couple of improvements on commit...
Ensured that $path is the expected value in the test
Added correct typehinit on commit to hook docs.
Ran the tests locally prior to commit.
Comment #42
fagoIt seems this caused some regressions: