framework/extensions/lock/extend.php

63 lines
2.2 KiB
PHP
Raw Normal View History

2015-07-28 14:05:55 +08:00
<?php
2015-09-04 11:02:04 +08:00
/*
* This file is part of Flarum.
*
2019-11-30 07:02:10 +08:00
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
2015-09-04 11:02:04 +08:00
*/
use Flarum\Api\Serializer\BasicDiscussionSerializer;
2020-12-09 03:21:00 +08:00
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Discussion\Discussion;
use Flarum\Discussion\Event\Saving;
2021-03-14 04:35:53 +08:00
use Flarum\Discussion\Filter\DiscussionFilterer;
use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Extend;
2015-10-11 13:45:07 +08:00
use Flarum\Lock\Access;
use Flarum\Lock\Event\DiscussionWasLocked;
use Flarum\Lock\Event\DiscussionWasUnlocked;
2021-03-14 04:35:53 +08:00
use Flarum\Lock\Query\LockedFilterGambit;
2015-10-11 13:45:07 +08:00
use Flarum\Lock\Listener;
use Flarum\Lock\Notification\DiscussionLockedBlueprint;
use Flarum\Lock\Post\DiscussionLockedPost;
2015-07-28 14:05:55 +08:00
return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/less/forum.less'),
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
new Extend\Locales(__DIR__.'/locale'),
(new Extend\Notification())
->type(DiscussionLockedBlueprint::class, BasicDiscussionSerializer::class, ['alert']),
2020-12-09 03:21:00 +08:00
(new Extend\ApiSerializer(DiscussionSerializer::class))
->attribute('isLocked', function (DiscussionSerializer $serializer, Discussion $discussion) {
return (bool) $discussion->is_locked;
})
->attribute('canLock', function (DiscussionSerializer $serializer, Discussion $discussion) {
return (bool) $serializer->getActor()->can('lock', $discussion);
}),
2020-12-09 03:21:00 +08:00
(new Extend\Post())
->type(DiscussionLockedPost::class),
2015-10-11 13:45:07 +08:00
2020-12-09 03:21:00 +08:00
(new Extend\Event())
->listen(Saving::class, Listener\SaveLockedToDatabase::class)
->listen(DiscussionWasLocked::class, Listener\CreatePostWhenDiscussionIsLocked::class)
->listen(DiscussionWasUnlocked::class, Listener\CreatePostWhenDiscussionIsUnlocked::class),
(new Extend\Policy())
->modelPolicy(Discussion::class, Access\DiscussionPolicy::class),
2021-03-14 04:35:53 +08:00
(new Extend\Filter(DiscussionFilterer::class))
->addFilter(LockedFilterGambit::class),
(new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
->addGambit(LockedFilterGambit::class),
];