- Issue created by @reinfate
- Merge request !10251Issue #3488403: Default images for the Image field are not recording file usage properly → (Open) created by reinfate
Does this duplicate one of the issues related to 🌱 Dealing with unexpected file deletion due to incorrect file usage Active or is this a newly-identified bug?
Checked the issue summary in https://www.drupal.org/project/drupal/issues/2821423 🌱 Dealing with unexpected file deletion due to incorrect file usage Active and this seems like a newly-identified bug
Some random tests failed, but I'm pretty sure it's not related to this issue.
- 🇺🇸United States smustgrave
Appears to need a rebase.
If you are another contributor eager to jump in, please allow the original poster @reinfate at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!
- Issue was unassigned.
- Status changed to Needs review
2 months ago 3:07pm 5 May 2025 - 🇺🇸United States smustgrave
Question what are the odds this could break contrib or custom code that could still be calling
\Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field_storage->uuid());
It will not result in a critical error, but yes, in that case, the usages will not be added or deleted properly.
I would say it is unlikely that there is a lot of code that works with file usage on behalf of the image module.
And the only solution that I could think of is to deprecate'image', 'default_image'
as 2nd and 3rd params in the file_usage service.The PR also needs an update hook to update existing records. I could add that, once there is a green light for the current solution.
- 🇺🇸United States smustgrave
If I had to guess deprecation would be the way to go on the safe side but not 100%
- 🇮🇳India roshanibhangale
Hi,
I have tested this ticket on Drupal 11.x.dev and its working as expcted for me.
Steps followed
- Add field type Image to any entity type.
- Add default image (in storage or field config)
- If the field is new, file usage is not added and the file is temporary
- If updating, file usage is added, but with wrong parameters, so /admin/content/files/usage/{file_id} throws a 500 while trying to load the "default_image" entity type.
Actual Result
- After applying the patch successfully, able to see the added image is showing as permanant and usage place.
Hence moving this ticket to RTBC +1
Attaching the screenshot for the reference.