I have a handful of file fields that have the following default Drupal behavior:
- User can upload a file
- User can upload another file in place
- User can remove file
Standard config. Whats happening is the user wants the file being replaced to be deleted before the new one is uploaded, and thus, avoiding the issue where files have their names replaced with _N identifiers to ensure unique filenames.
This is because they are referencing physical file paths from the menu and WYSIWYG fields - which means the old replaced file is being referenced instead of the new one. Since these are core file fields and over 100 files have been uploaded, I cannot switch out to a Media field. I'm also not sure if that would even solve the problem at hand, anyway.
Is there any way I can hook into this widget via form alter, detect a click on the upload field, and if a new file is being added, delete the old one in place so that the file being uploaded the name stays intact and thus preserving link targets?
I have looked at the form with both
hook_field_widget_form_alter - but I am not really seeing anything I can use to hook into.