Logical deletion
Logical deletion allows you to disable items instead of physically deleting them.
This is useful in a variety of situations. For example:
- when items must legally never be deleted (cancelled invoices, ...)
- when an item cannot be deleted because it is referenced by other items
- when an administrator must review, confirm or reverse deletions made by users
- ...
Neos allows you to configure logical deletion entity view per entity view. By default, logically deleted items are automatically ignored when a entity view retrieves data.
Status property on an entity
The first step to enable logical deletion is to define a Status property on the entity you want to logically delete.
This property stores a value that indicates whether an item is active. You can select one of the entity's properties of type Boolean, Enum, Integer, Long, or String.
Then, the Active status value and Inactive status value need to be set.
These are the values that will be stored in the Status property to indicate the state of an item.
Note
In most cases, the selected status property should be Required, and its Default value should be the same as the Active status value.
Note
When an entity inherits from a parent entity, it also inherits the Status property, Active status value and Inactive status value. In that case, their values cannot be changed except on the parent entity where they were first configured.
Filter mode on an entity view
The Filter mode indicates how items retrieved by the entity view are filtered. It also determines whether logical deletion is possible and the behavior of UI views based on the entity view.
All items
All items are retrieved, no filter is applied.
Logical deletion is unavailable because logically deleted items would be removed from the UI view datasource but reappear when refreshing data.
Note
This is the default value when no Status property is set on the entity.
Active items only
Only active items are retrieved, the filter is automatically applied.
Logical deletion is available.
Note
This is the default value when a Status property is set on the entity.
Inactive items only
Only inactive items are retrieved, the filter is automatically applied.
Logical deletion is unavailable because logically deleted items cannot be logically deleted again.
This mode is likely to be used to create administration screens where logically deleted items can be reactivated or physically deleted by an administrator.
Deletion mode on an entity view
The Deletion mode indicates whether items are physically or logically deleted.
Warning
This influences how UI views based on the entity view behave when deleting an item.
To help you understand how UI views will behave, an information recap is displayed under the combobox.
Logical
When a DELETE request is received, the Status property of the item is automatically updated using the Inactive status value instead of deleting the item.
Note
This mode can only be selected when Filter mode is Active items only.
The Status property does not need to be included in the properties of the entity view for the logical deletion to work.
Physical
When a DELETE request is received, an attempt to physically remove the item is made.
This attempt can fail, for example, when the item is referenced by other items.
Note
This is the default value.
UI view behavior based on the entity and entity view configuration
Depending on the configuration made on the entity and entity view they are based on, UI views will behave differently when deleting items.
Simple physical deletion
When deleting an item, the UI view sends a DELETE request to the server. The servers attempts to physically delete the item.
If the deletion fails, an error message is displayed to the user.
Note
This is the standard behavior.
Logical deletion when physical deletion fails
When deleting an item from the UI, the UI view sends a DELETE request as usual.
If the response indicates that the item could not be deleted because it is referenced by other items, the UI view automatically sends an UPDATE request to update the Status property with the Inactive status value to logically delete the item.
Otherwise, an error message is displayed to the user.
This behavior only occurs when:
Status property,Active status value, andInactive status valueare set on the entityFilter modeisActive items onlyon the entity viewDeletion modeisPhysicalon the entity viewDeletion allowedandUpdate allowedaretrueon the entity view- the entity view includes a property that is not
Server side read onlyand uses theStatus propertyas itsSource
Warning
This behavior is automatically activated when all the conditions are met.
It is not possible to disable it on a specific UI view. You need to create another entity view for that.
Manual logical deletion / Reactivation of logically deleted items
Since logical deletion is only based on the value of a property, items can easily be logically deleted or reactivated by updating the value of the Status property.
Warning
However, to avoid unforeseen behaviors in the UI when logically deleting or reactivating items, we recommend you avoid changing the Status property value in the UI and use server methods instead.
For this reason, entity view properties that use the Status property as their source are always Client side read only.