-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
SilverStripe Soft Delete Module | ||
================== | ||
# SilverStripe Soft Delete Module | ||
|
||
Add a soft delete behaviour to your dataobjects. Objects are simply marked as deleted and kept in the database. | ||
|
||
|
@@ -9,57 +8,78 @@ ModelAdmin and SecurityAdmin are extended to add a new GridField action that rep | |
|
||
This module depends on [lekoala/silverstripe-cms-actions](https://github.com/lekoala/silverstripe-cms-actions) for displaying delete buttons | ||
|
||
How to use | ||
================== | ||
# How to use | ||
|
||
Simply replace your calls from delete to softDelete. | ||
|
||
New extensions hooks are provided to avoid side effects (onBeforeSoftDelete, onAfterSoftDelete). | ||
These are ideals if you have child records that need to be soft deleted with their parent. | ||
|
||
Config options | ||
================== | ||
|
||
SilverStripe\Admin\ModelAdmin: | ||
softdelete_from_list: true | ||
softdelete_from_list_exclude: [] | ||
extensions: | ||
- SoftDeleteModelAdmin | ||
SilverStripe\Admin\SecurityAdmin: | ||
softdelete_from_list: true | ||
softdelete_from_list_exclude: [] | ||
extensions: | ||
- SoftDeleteSecurityAdmin | ||
# Config options | ||
|
||
```yml | ||
SilverStripe\Admin\ModelAdmin: | ||
softdelete_from_list: true | ||
softdelete_from_list_exclude: [] | ||
extensions: | ||
- SoftDeleteModelAdmin | ||
SilverStripe\Admin\SecurityAdmin: | ||
softdelete_from_list: true | ||
softdelete_from_list_exclude: [] | ||
extensions: | ||
- SoftDeleteSecurityAdmin | ||
``` | ||
You can configure: | ||
- softdelete_from_list: show delete button on a line. Enabled by default. | ||
- softdelete_from_list_exclude: hide the delete button for these classes even if enabled globally | ||
Prevent accidental deletion | ||
================== | ||
- softdelete_from_list: show delete button on a line. Enabled by default. | ||
- softdelete_from_list_exclude: hide the delete button for these classes even if enabled globally | ||
# Prevent accidental deletion | ||
By default, the module will prevent any delete from happening. To allow deletion, you must set | ||
SoftDeletable:$prevent_delete = false | ||
```php | ||
SoftDeletable:$prevent_delete = false | ||
``` | ||
|
||
The only way from the CMS UI to delete a record is to go to a soft deleted record | ||
and click "Really delete" which will call "forceDelete" on the record. | ||
|
||
Disable filtering | ||
================== | ||
# Disable filtering | ||
|
||
You can disable filtering globally, using | ||
|
||
SoftDeletable::$disable = true | ||
```php | ||
SoftDeletable::$disable = true | ||
``` | ||
|
||
Or at query level | ||
|
||
$dataQuery->setQueryParam('SoftDeletable.filter',false) | ||
```php | ||
$dataQuery->setQueryParam('SoftDeletable.filter',false) | ||
``` | ||
|
||
# Filtering on ids | ||
|
||
By default, this module will let you return soft deleted records if you | ||
ask them specifically by ID. This is by design to prevent things breaking accidentally. | ||
If you want to make sure you don't display soft deleted records, make | ||
sure to implement a proper canView() method that fits your usage. | ||
|
||
An alternative option, is to disable that feature: | ||
|
||
```yml | ||
SoftDeletable: | ||
filters_on_id: true | ||
``` | ||
Keep in mind that `DataObject::get_by_id();` can get cached and it can lead to tricky scenarios. | ||
|
||
# Compatibility | ||
|
||
Compatibility | ||
================== | ||
Tested with 4.4+ | ||
|
||
Maintainer | ||
================== | ||
# Maintainer | ||
|
||
LeKoala - [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters