Problem/Motivation
The current behavior of the Media File Delete module prevents deletion of files if they are referenced by other entities. While this is generally correct, it becomes problematic in real-world scenarios — especially on sites using content revisions, paragraphs, and translation workflows — where many of the file usage references are not meaningful to editors.
This leads to two major problems:
- Files are retained unnecessarily even after the Media entity is deleted, due to lingering usage references from non-default revisions or translations.
- Media entities become orphaned when users delete files directly from the file listing (/admin/content/files), leaving clutter in the media library.
These issues are compounded by known limitations in Drupal core’s file usage tracking system:
- #1239558: File usage from non-default revisions is not released, causing files to linger even after deletion.
- #2821423: File usage tracking is fragile and can result in unexpected file deletions or retention due to incorrect usage counts.
- #3364744: The current file usage API is unreliable and lacks a comprehensive entity usage model, making it difficult to determine actual usage across complex entity relationships.
These limitations make it difficult for editors to confidently manage media and file assets, especially in large or editorially complex sites.
Proposed resolution
This patch introduces two new configurable behaviors:
- Force delete from file system irrespective of usage
- Delete media when deleting files
Allows deletion of files even when referenced.
Includes two options:
- Delete the file permanently
- Archive file to private file system (requires private file system configuration)
Ensures that when a File entity is deleted, any associated Media entity is also deleted to prevent orphaned media.
User interface changes
- Reorganized settings form with clear headings and conditional visibility.
- Contextual help text added to guide users on configuring the private file system.
- Graceful fallback and logging added to prevent WSOD when archiving fails due to misconfiguration.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | media_file_delete_cleanup.patch | 11.92 KB | dsrikanth |
| Media-File-Delete-settings-12-10-2025_03_23_PM.png | 164 KB | dsrikanth |
Comments
Comment #2
dsrikanth commentedComment #3
dsrikanth commentedComment #4
dsrikanth commentedComment #5
dsrikanth commented