Drupal Form File Usage Module Automates File Tracking for Custom Forms
A new Drupal module called Form File Usage has been released to automate file usage management for custom forms built with Drupal's Form API. Developed by Alexander Shabanov, the project addresses a common issue where files uploaded through managed_file and CKEditor-based form elements can be removed by Drupal cron because their usage is not automatically tracked.
The module automatically promotes newly uploaded files to permanent status, registers usage records, and removes those records when files are no longer referenced. If a file has no remaining usages elsewhere on a site, it is demoted back to temporary status, allowing Drupal's cleanup processes to remove it safely. According to the project documentation, the module uses a state-synchronisation approach that compares current form values against existing file usage records rather than relying on historical form data.
Support for CKEditor 5 is included through automatic parsing of embedded image references, enabling inline images to be tracked without additional custom code. The project also provides automatic configuration detection for forms extending ConfigFormBase, support for custom storage contexts, and a developer API that can be used in block plugins, Layout Builder components, Commerce integrations and other advanced implementations.
For standard configuration forms, developers can enable tracking by adding #track_file_usage => TRUE to supported form elements. Version 1.0.0 was released on 27 May 2026, supports Drupal 10 and 11, and is covered by Drupal's security advisory policy. The project page currently reports one site installation.

