Clear image style cache after replacing file

Created on 6 November 2023, about 1 year ago

Problem/Motivation

When utilizing the replace file functionality on an image field that uses for example the Image Widget Crop, the style thumbnail isn't updated which leads to having to manually flush styles to crop newly replaced images. It would be great if we added an image_path_flush when the user chooses to replace the file (same way they do in Media Entity File Replace).

Steps to reproduce

  1. Create a new media entity type with an image field
  2. Enable the replace feature on that field with file_field_replace
  3. Setup the Image Crop Widget and create crop styles
  4. Setup the new media's form widget for the image crop widget
  5. Add one of the newly created media entities and upload an image and save
  6. Replace that image with another that has an identical name, but different file. Verify that that crop preview and thumbnail shows an older image

Proposed resolution

We should be able to do something similar to this, need to cast because the callback currently returns a string.

// Clear image cache for this file if it is a replace.
if ((int) $replace === 1) {
    image_path_flush($file->getFileUri());
}
✨ Feature request
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States j-barnes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024