From 2a21725fe3172a9b4b888dcf67e874320d144cd3 Mon Sep 17 00:00:00 2001 From: Rafael Horvat Date: Sun, 28 Jun 2020 20:47:32 +0200 Subject: [PATCH] Firing 2 new events for tags: Creating & Deleting (#86) --- .../tags/src/Command/CreateTagHandler.php | 3 ++ .../tags/src/Command/DeleteTagHandler.php | 3 ++ extensions/tags/src/Event/Creating.php | 43 +++++++++++++++++++ extensions/tags/src/Event/Deleting.php | 36 ++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 extensions/tags/src/Event/Creating.php create mode 100644 extensions/tags/src/Event/Deleting.php diff --git a/extensions/tags/src/Command/CreateTagHandler.php b/extensions/tags/src/Command/CreateTagHandler.php index 95b98962c..9133cdf27 100644 --- a/extensions/tags/src/Command/CreateTagHandler.php +++ b/extensions/tags/src/Command/CreateTagHandler.php @@ -9,6 +9,7 @@ namespace Flarum\Tags\Command; +use Flarum\Tags\Event\Creating; use Flarum\Tags\Tag; use Flarum\Tags\TagValidator; use Flarum\User\AssertPermissionTrait; @@ -65,6 +66,8 @@ class CreateTagHandler } } + event(new Creating($tag, $actor, $data)); + $this->validator->assertValid($tag->getAttributes()); $tag->save(); diff --git a/extensions/tags/src/Command/DeleteTagHandler.php b/extensions/tags/src/Command/DeleteTagHandler.php index 55aadc163..1edb140b5 100644 --- a/extensions/tags/src/Command/DeleteTagHandler.php +++ b/extensions/tags/src/Command/DeleteTagHandler.php @@ -9,6 +9,7 @@ namespace Flarum\Tags\Command; +use Flarum\Tags\Event\Deleting; use Flarum\Tags\TagRepository; use Flarum\User\AssertPermissionTrait; @@ -42,6 +43,8 @@ class DeleteTagHandler $this->assertCan($actor, 'delete', $tag); + event(new Deleting($tag, $actor)); + $tag->delete(); return $tag; diff --git a/extensions/tags/src/Event/Creating.php b/extensions/tags/src/Event/Creating.php new file mode 100644 index 000000000..037307a52 --- /dev/null +++ b/extensions/tags/src/Event/Creating.php @@ -0,0 +1,43 @@ +tag = $tag; + $this->actor = $actor; + $this->data = $data; + } +} diff --git a/extensions/tags/src/Event/Deleting.php b/extensions/tags/src/Event/Deleting.php new file mode 100644 index 000000000..79627552a --- /dev/null +++ b/extensions/tags/src/Event/Deleting.php @@ -0,0 +1,36 @@ +tag = $tag; + $this->actor = $actor; + } +}