Problem/Motivation
The module provides an option to enable Trash support on the File entity, but I believe the File entity will require some special handling in order for it to work in a trash-like manner.
The idea being that moving a file to the trash should ideally also hide the file from the public, e.g. by moving them to a private://trash_files/ folder or something until they're restored.
There are some modules that do something similar we can take inspiration from:
- https://www.drupal.org/project/unpublished_file
- https://www.drupal.org/project/media_files_handler
- https://www.drupal.org/project/file_visibility
Proposed resolution
If it's decided that the additional complexity involved in trying to support might not be worth the hassle.
We can either explicitly disable the File entity from being supported, or try to support "soft-deletions" of the underlying file.
Remaining tasks
N/A
Issue fork trash-3583917
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
codebymikey commentedComment #5
amateescu commentedThere are a couple of problems with moving to the
private://stream wrapper:- it might not be configured on all sites
- we don't know whether the file was using the private scheme before being trashed (unless we encode the scheme in the new file name)
But I think we can implement a "good enough" solution that doesn't involve
private://, just move the file to an unguessable location in the public scheme.Comment #6
codebymikey commentedI have to say, I'm extremely impressed with the solution here!
I was under the impression it'd be a bit of a goliath task to achieve, but moving it into a hidden
.trashedsubdirectory makes perfect sense without introducing too much complexity.During my test, ran into an issue with compatibility with the
path_aliasalias integration, so I've pushed the code up for that for you to review.There was also a tiny bug relating to how
dirname()works with URIs for top-level files and it resolving to a directory calledpublic:in the root of the project and failing to write to it (the tests only passed because it created the initialpublic:folder as part of the setup), so updated the code to use the file_system service to resolve them instead.The final commit is mainly for edge-case handling (relating to me being unable to restore a file after I ran into the path_alias crash), but if you don't feel it's necessary to keep, feel free to remove it.
Comment #9
amateescu commentedYour changes look great, thanks! Made a few adjustments and merged to 3.1.x and 3.x.
Comment #11
codebymikey commentedThere's one more bug I ran into while testing the File entity integration.
It seems there's still other parts of the code (in particular the EntityRestoreForm) calling
\Drupal\Core\Entity\EntityInterface::toUrl()without checking that the entity supports it. So adding a fix and functional test and will mark for Review shortly.One other Drupal quirk I just realized is that if you call
/file/$fid/deletewithout a destination query string, it'll result in a crash due to how\Drupal\Core\Form\ConfirmFormHelper::buildCancelLink()/code> works.Comment #12
codebymikey commentedThe issue was actually related to the latest version of the #3376216: Translation support patch, since it includes a link to the entity during restorations.
Will push the fix there instead.