When a file is uploaded through the WYSIWYG using this plugin, it is stored as a "Temporary" file, not "Permanent". So it will be deleted by Drupal when cleaning the temporary file on cron run.
We can clearly see the "Temporary" state of the uploaded files in the "Files" tab of the Content section of the administration.
Proposed solution
The most convenient solution would be to add a file usage for the uploaded file, so it could be linked to the content, and therefore be cleaned up automatically if the content is deleted. A file with a file usage is always marked as permanent (@see src/FileUsage/FileUsageBase.php).
But if it's difficult to link a file to an entity through the WYSIWYG interface, at least use $file->setPermanent() in the upload form submit.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | Screenshot 2022-09-27 at 15.33.06.png | 23.41 KB | saidatom |
| #6 | permanent-file.png | 5.88 KB | eigentor |
| #2 | file-upload-marked-permanent-3057895-2.patch | 690 bytes | mattew |
Issue fork editor_file-3057895
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mattew commentedHere is a proposal for a simple patch.
Comment #3
jdearie commentedFWIW
I was testing this module through simplytest.me this morning - the file I uploaded was marked as Permanent. After reading this issue (only a few minutes after performing an upload), I went to /admin/content/files and saw that the file was there and listed as Permanent
I ran Cron and the file was still there (as expected since it's marked permanent).
Comment #4
eigentor commentedThere is a scenario where uploaded files are temporary indeed:
When uploaded inside a textarea in Webform.
Matthew's patch fixes that.
So it would be an improvement to commit it.
There might be other situations where files are uploaded to a textarea that is not a field created with Drupal's field system where the same thing happens.
Comment #5
eigentor commentedComment #6
eigentor commentedStill the patch needs work: Even though the file is listed as permanent in the file overview, it is said to be used still in 0 places:
Webform itself had a similar issue with any inline file and solved it differently, maybe the patch give insights: https://www.drupal.org/project/webform/issues/3005297
Comment #7
mxr576+1 on how this was solved in Webform
https://git.drupalcode.org/project/webform/-/blob/6.1.3/includes/webform...
https://git.drupalcode.org/project/webform/-/blob/6.1.3/src/Plugin/Webfo...
Comment #8
stefvanlooveren commentedI have this use case: I'm allowing webmasters to upload images via CKEditor in a custom config form. So apparently, cron sweeps it on a daily basis.
The patch will work, but "0 places" in the files list feels like it might cause problems in the future.
I do not have an idea on how to handle this tbh.
Comment #9
saidatomThis patch works fine for me.

As you can see in screenshot:
And html:
<a data-entity-type="file" data-entity-uuid="dc22935f-fb41-4e7c-a3ce-f6b99f98b886" href="/sites/default/files/inline-files/Screenshot%202022-09-27%20at%2009.55.39_0.png">Screenshot 2022-09-27 at 09.55.39_0.png</a>Warning
If you have the "Limit allowed HTML tags and correct faulty HTML" filter enabled, you should ensure that dragging the button in the toolbar successfully added the data-entity-type and data-entity-uuid attributes to your tag.
Comment #10
claudiu.cristeaComment #15
duaelfrFixed in 1.x and cherry picked in 2.x.
File usage is tracked for nodes by default so files uploaded in webforms or custom forms should be tracked differently.
Comment #16
duaelfrThank you all for your work on this one!
Sorry for the huge delay :/