Firing 2 new events for tags: Creating & Deleting (#86)

This commit is contained in:
Rafael Horvat 2020-06-28 20:47:32 +02:00 committed by GitHub
parent 0c1869b93e
commit 2a21725fe3
4 changed files with 85 additions and 0 deletions

View File

@ -9,6 +9,7 @@
namespace Flarum\Tags\Command; namespace Flarum\Tags\Command;
use Flarum\Tags\Event\Creating;
use Flarum\Tags\Tag; use Flarum\Tags\Tag;
use Flarum\Tags\TagValidator; use Flarum\Tags\TagValidator;
use Flarum\User\AssertPermissionTrait; use Flarum\User\AssertPermissionTrait;
@ -65,6 +66,8 @@ class CreateTagHandler
} }
} }
event(new Creating($tag, $actor, $data));
$this->validator->assertValid($tag->getAttributes()); $this->validator->assertValid($tag->getAttributes());
$tag->save(); $tag->save();

View File

@ -9,6 +9,7 @@
namespace Flarum\Tags\Command; namespace Flarum\Tags\Command;
use Flarum\Tags\Event\Deleting;
use Flarum\Tags\TagRepository; use Flarum\Tags\TagRepository;
use Flarum\User\AssertPermissionTrait; use Flarum\User\AssertPermissionTrait;
@ -42,6 +43,8 @@ class DeleteTagHandler
$this->assertCan($actor, 'delete', $tag); $this->assertCan($actor, 'delete', $tag);
event(new Deleting($tag, $actor));
$tag->delete(); $tag->delete();
return $tag; return $tag;

View File

@ -0,0 +1,43 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Tags\Event;
use Flarum\Tags\Tag;
use Flarum\User\User;
class Creating
{
/**
* @var Tag
*/
public $tag;
/**
* @var User
*/
public $actor;
/**
* @var array
*/
public $data;
/**
* @param Tag $tag
* @param User $actor
* @param array $data
*/
public function __construct(Tag $tag, User $actor, array $data)
{
$this->tag = $tag;
$this->actor = $actor;
$this->data = $data;
}
}

View File

@ -0,0 +1,36 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Tags\Event;
use Flarum\Tags\Tag;
use Flarum\User\User;
class Deleting
{
/**
* @var Tag
*/
public $tag;
/**
* @var User
*/
public $actor;
/**
* @param Tag $tag
* @param User $actor
*/
public function __construct(Tag $tag, User $actor)
{
$this->tag = $tag;
$this->actor = $actor;
}
}