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.

Command icon 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

mattew created an issue. See original summary.

mattew’s picture

StatusFileSize
new690 bytes

Here is a proposal for a simple patch.

jdearie’s picture

FWIW

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).

eigentor’s picture

There 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.

eigentor’s picture

Status: Active » Needs work
eigentor’s picture

StatusFileSize
new5.88 KB

Still 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:

permanent file

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

stefvanlooveren’s picture

I 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.

saidatom’s picture

StatusFileSize
new23.41 KB

This patch works fine for me.
As you can see in screenshot:
print

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.

claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community

DuaelFr made their first commit to this issue’s fork.

  • mattew authored 2ef873d0 on 8.x-1.x
    Issue #3057895 by claudiu.cristea, mattew, eigentor, saidatom,...

  • mattew authored 6229d6ae on 2.x
    Issue #3057895 by claudiu.cristea, mattew, eigentor, saidatom,...
duaelfr’s picture

Version: 8.x-1.4 » 8.x-1.x-dev
Status: Reviewed & tested by the community » Fixed

Fixed 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.

duaelfr’s picture

Thank you all for your work on this one!
Sorry for the huge delay :/

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.