I would like to develop a plugin to help better maintain data integrity between related records. Something like the following:
- When deleting an entry, check whether the entry has "reverse related entries" (i.e. other entries that relate to this entry), and if so, interrupt the delete process and show a warning — something like: "This entry is currently being referenced by 'xyz' entry. Are you sure you want to delete this entry?". If the user selects 'cancel', then cancel the delete process. (Perhaps in a future version of craft this should even happen by default if the entries field is 'required' on the reverse related entry.)
- Even better, would be an option to cascade delete "reverse-related" entries, with a message that said something like: "Are you sure you want to delete this entry and all related data?", which would then initiate a cascading delete process. Obviously you would want to specify which 'related entries' fields will initiate the cascade — perhaps a checkbox on the 'related entries' field settings that read "when deleting related entries, provide an option to also delete this entry".
From what I understand, as of a recent update, I believe we can now stop processes from within an event method (i.e. onBeforeDeleteEntry
). So I can see how one might develop the first option fairly easily.
The second option is a bit more complicated, without also developing a 'custom related entries fieldtype'. Something that I would prefer to not do (to maintain future compatibility). Perhaps a separate panel that has a drop down to select from 'all related entries fields', those that should initiate a cascade, that can be used as a lookup table within the onBeforeDeleteEntry
event?
I'm just curious if anyone has attempted anything like this? And/or if anyone can recommend a good approach.