diff --git a/README.md b/README.md index d4893f1..fe95049 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,11 @@ or use the purge option: $table->delete($entity, ['purge' => true]); ``` +## Detecting trashing +If you need to distinguish between deletion and trashing the behavior +adds the ['trash' => true ] option to the afterDelete event +it creates when trashing. + ### Cascading deletion If you'd like to have related records marked as trashed when deleting a parent diff --git a/src/Model/Behavior/TrashBehavior.php b/src/Model/Behavior/TrashBehavior.php index d6b4b65..098cb16 100644 --- a/src/Model/Behavior/TrashBehavior.php +++ b/src/Model/Behavior/TrashBehavior.php @@ -27,6 +27,8 @@ */ class TrashBehavior extends Behavior { + public const DELETE_OPTION_NAME = 'trash'; + /** * Default configuration. * @@ -118,6 +120,8 @@ public function beforeDelete(EventInterface $event, EntityInterface $entity, Arr return; } + $options[self::DELETE_OPTION_NAME] = true; + /** @var \Cake\ORM\Table $table */ $table = $event->getSubject(); $table->dispatchEvent('Model.afterDelete', [