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:

  1. Files are retained unnecessarily even after the Media entity is deleted, due to lingering usage references from non-default revisions or translations.
  2. 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:

  1. Force delete from file system irrespective of usage
  2. 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)

  3. Delete media when deleting files
  4. 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.
  • New settings

Comments

dsrikanth created an issue. See original summary.

dsrikanth’s picture

Issue summary: View changes
dsrikanth’s picture

Issue summary: View changes
dsrikanth’s picture

Issue summary: View changes
dsrikanth’s picture

StatusFileSize
new11.92 KB