Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I have an entity reference field type for file entities on a custom block type. When a file is added (referenced) on the field, the usage is not recorded. This is a problem if you enable orphan file deletion.
Before working on this read #2821423: Dealing with unexpected file deletion due to incorrect file usage.
Steps to reproduce
Proposed resolution
TBD
Remaining tasks
TBD
User interface changes
N/A
Comments
Comment #2
catchAt least major if not critical.
Comment #4
xjmYeah I think this is critical, since it will also result in unexpected deletion of the files.
Comment #5
effulgentsia CreditAttribution: effulgentsia at Acquia commentedIn #2831274-200: Bring Media entity module to core as Media module, I suggested removing the ability to make ER fields to file entities. Here's what I said in that comment:
There was a UX call following that comment where people on the UX team +1'd that suggestion, but I don't have the link to that recording at the moment (though I can dig it up if needed).
However, we don't have Media field in core yet, and even once we do, I don't know if we have sufficient consensus on removing ER fields to file entities. So, I don't know if we want to fix this issue by making usage tracking work, or if we want to "fix" it by removing ER fields to files.
Comment #6
effulgentsia CreditAttribution: effulgentsia at Acquia commentedI discussed this with @xjm, @catch, @alexpott, and @cottser. We agreed to keep this Critical for now, since it is a data integrity bug, so tagging it as triaged.
#2821423: Dealing with unexpected file deletion due to incorrect file usage is the issue for dealing with all the file usage problems more systemically, but that's a Plan issue for now, so the individual bugs are still independent issues.
#2862461: When adding a reference field, remove "File" from the offered entity types is the issue for deprecating ER fields to file entities in favor of using Media fields instead, per #5. However, while we can remove the capability from the UI, we'll still need to deal with BC for sites that already have this.
Therefore, this issue still needs to be addressed.
Comment #7
Wim LeersBut that'd be breaking the integrity of the data modeling capabilities of Drupal. It'd also be a BC break.
Here's an alternative proposal:
FileFieldItemList::postSave()
+FileFieldItemList::delete()
+FileFieldItemList::deleteRevision()
tohook_entity_insert()
+hook_entity_update()
+hook_entity_delete()
+hook_entity_revision_delete()
implementations owned by thefile
moduleinstanceof EntityReferenceFieldItemList
, i.e. for every entity reference fieldComment #8
catchNow that #2801777: Give users the option to prevent drupal from automatically marking unused files as temporary is in, this no longer results in unexpected file deletion. #2821423: Dealing with unexpected file deletion due to incorrect file usage is open as a critical meta-issue to discuss the broader approach on this. So I'm going to downgrade this to major after discussion with @xjm and @cilefen, since we feel effort would be better spent on replacing the file_usage system at this point. We can still fix this bug of course as a major.
Comment #16
quietone CreditAttribution: quietone at PreviousNext commentedUpdate IS.