<p>Yo, <a href="https://docs.craftcms.com/v3/extend/soft-deletes.html" rel="nofollow noreferrer">read the docs</a>.</p>

<p><em>He says to himself quietly, having not visited the plugin docs in a while.</em></p>

CC BY-SA 4.0
2020-02-05T02:13:06.027Z
haha... I lol'd.
Brad Bell
CC BY-SA 4.0
2020-02-04T22:01:35.717Z
2020-02-04T22:01:35.717Z
Ben Parizek
<p>I have a custom Element (a Form Element) that adds a custom content table for each Element that gets created (similar to how the Matrix Field creates a custom content table for each field). Users can submit data to another custom Element (Form Entry Element) that stores data in that content table.</p>

<p>In my case, when a Form Element is soft-deleted it would need to preserve the custom field layout, tabs, fields, and related content table for the Form Element, along with all the related Form Entry Elements that get added to the content table.  And then, if the item was not restored, when Craft purges old Elements from the Trash, all of those items would also need to be deleted.</p>

<p>What are the general considerations I need to know about to handle soft deletes correctly? Are there any specific files or methods in the Craft codebase I can take a closer look at to better understand how this behavior works at the point of the initial soft delete and during the cleanup when things get hard deleted?</p>

<elementtype><soft-deletes>
How to handle soft delete behavior for a custom Element with custom content tables
# How to handle soft delete behavior for a custom Element with custom content tables

(Asked by: username_0 on 2020-02-04)

I have a custom Element (a Form Element) that adds a custom content table for each Element that gets created (similar to how the Matrix Field creates a custom content table for each field). Users can submit data to another custom Element (Form Entry Element) that stores data in that content table.

In my case, when a Form Element is soft-deleted it would need to preserve the custom field layout, tabs, fields, and related content table for the Form Element, along with all the related Form Entry Elements that get added to the content table. And then, if the item was not restored, when Craft purges old Elements from the Trash, all of those items would also need to be deleted.

What are the general considerations I need to know about to handle soft deletes correctly? Are there any specific files or methods in the Craft codebase I can take a closer look at to better understand how this behavior works at the point of the initial soft delete and during the cleanup when things get hard deleted?

**Tags:** elementtype, soft-deletes


---

## 1 answers

### Answer by username_0 on 2020-02-04. Score: 1

Yo, [read the docs](https://docs.craftcms.com/v3/extend/soft-deletes.html).

*He says to himself quietly, having not visited the plugin docs in a while.*

> **Comments:**
> **username_1**: haha... I lol'd.  

---

