Active
Project:
Storage Entities
Version:
1.1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Apr 2021 at 10:22 UTC
Updated:
26 Aug 2022 at 04:42 UTC
Jump to comment: Most recent
When deleting a parent entity (e.g. node) that has references to storage entities, it would ideal if there was a mechanism to automatically clean up any "orphaned" storage entities. Likely this is something that should be configurable in the storage type.
The steps to go through in hook_entity_delete hook would be:
- look up the entity's bundle
- look for reference fields that allow storage entities
- if any fields, look for values in the field(s)
- foreach value, look up the storage type
- if the storage type configured to remove orphaned data, delete it
Comments
Comment #2
mxh commentedVery good idea, but not easy to solve. Might also be worth to consider involving Entity Usage into this mechanic.
Comment #3
mxh commentedComment #4
mandclu commentedEntity Reference Purger sounds like it will do precisely what has been proposed by this issue, so no need to replicate that functionality.
Comment #5
mandclu commentedWhoops that module fixes the opposite issue, parents that continue to point to deleted children. Paragraphs Clean is closer to what we want here, but would need to be adapted, as well as add a hook_entity_delete option.
Comment #6
joelseguinI've tested the automatic removal of a storage entity with the Composite Reference module (https://www.drupal.org/project/composite_reference) and it worked great out of the box. Very easy to set up on a per reference field basis. This approach would definitely meet most of my use cases for a light approach to adding multiple fields to a node (vs the full Paragraph experience).
** One minor caveat with the Composite Reference module: When using the Inline Entity Form is that if I simply remove my storage entity on the form it will not automatically get deleted (obviously because the trigger is the deletion of the node itself). I believe that's just a very minor inconvenience at this point.
Another thought I had to tackle this problem was to make use of the ECA module (https://www.drupal.org/project/eca) to handle the deletion of orphaned storage entities on cron run (which should be doable).