mirror of
https://github.com/flarum/framework.git
synced 2024-11-23 21:19:18 +08:00
Use new Model extender
This commit is contained in:
parent
519fc3d970
commit
6fa5cc4408
|
@ -9,7 +9,9 @@
|
|||
|
||||
use Flarum\Approval\Access;
|
||||
use Flarum\Approval\Listener;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Post\Post;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
return [
|
||||
|
@ -20,6 +22,14 @@ return [
|
|||
(new Extend\Frontend('admin'))
|
||||
->js(__DIR__.'/js/dist/admin.js'),
|
||||
|
||||
// Discussions should be approved by default
|
||||
(new Extend\Model(Discussion::class))
|
||||
->default('is_approved', true),
|
||||
|
||||
// Posts should be approved by default
|
||||
(new Extend\Model(Post::class))
|
||||
->default('is_approved', true),
|
||||
|
||||
function (Dispatcher $events) {
|
||||
$events->subscribe(Listener\AddPostApprovalAttributes::class);
|
||||
$events->subscribe(Listener\ApproveContent::class);
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
namespace Flarum\Approval\Listener;
|
||||
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Event\ConfigureModelDefaultAttributes;
|
||||
use Flarum\Event\GetModelIsPrivate;
|
||||
use Flarum\Flags\Flag;
|
||||
use Flarum\Post\Event\Saving;
|
||||
|
@ -24,21 +23,10 @@ class UnapproveNewContent
|
|||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigureModelDefaultAttributes::class, [$this, 'approveByDefault']);
|
||||
$events->listen(Saving::class, [$this, 'unapproveNewPosts']);
|
||||
$events->listen(GetModelIsPrivate::class, [$this, 'markUnapprovedContentAsPrivate']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureModelDefaultAttributes $event
|
||||
*/
|
||||
public function approveByDefault(ConfigureModelDefaultAttributes $event)
|
||||
{
|
||||
if ($event->isModel(Post::class) || $event->isModel(Discussion::class)) {
|
||||
$event->attributes['is_approved'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Saving $event
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user