mirror of
https://github.com/flarum/core.git
synced 2025-07-30 05:00:56 +02:00
Give the is_approved attribute a default value on new Post models
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Flarum\Approval\Listener;
|
||||
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Event\ConfigureModelDefaultAttributes;
|
||||
use Flarum\Event\PostWillBeSaved;
|
||||
use Flarum\Flags\Flag;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
@@ -21,9 +23,20 @@ class UnapproveNewContent
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigureModelDefaultAttributes::class, [$this, 'approveByDefault']);
|
||||
$events->listen(PostWillBeSaved::class, [$this, 'unapproveNewPosts']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureModelDefaultAttributes $event
|
||||
*/
|
||||
public function approveByDefault(ConfigureModelDefaultAttributes $event)
|
||||
{
|
||||
if ($event->isModel(Post::class)) {
|
||||
$event->attributes['is_approved'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWillBeSaved $event
|
||||
*/
|
||||
|
Reference in New Issue
Block a user