mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 22:43:41 +08:00
Firing 2 new events for tags: Creating & Deleting (#86)
This commit is contained in:
parent
0c1869b93e
commit
2a21725fe3
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
|
|
43
extensions/tags/src/Event/Creating.php
Normal file
43
extensions/tags/src/Event/Creating.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
36
extensions/tags/src/Event/Deleting.php
Normal file
36
extensions/tags/src/Event/Deleting.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user