-
Notifications
You must be signed in to change notification settings - Fork 1
/
extend.php
64 lines (49 loc) · 2.02 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Alter\GuestPosting;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Post\Post;
use Flarum\User\Event\Saving;
use FoF\Polls\Api\Serializers\PollSerializer;
use FoF\Polls\Poll;
return [
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js'),
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js'),
new Extend\Locales(__DIR__ . '/resources/locale'),
(new Extend\Middleware('forum'))
->add(GuestSessionMiddleware::class),
(new Extend\Middleware('api'))
->add(GuestSessionMiddleware::class),
(new Extend\Formatter)
->configure(Formatter\ConfigureMentions::class)
->render(Formatter\FormatPostMentions::class),
(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(ForumAttributes::class),
(new Extend\ApiSerializer(DiscussionSerializer::class))
->attribute('guest_username', function (DiscussionSerializer $serializer, Discussion $discussion) {
return $discussion->guest_username;
}),
(new Extend\ApiSerializer(PostSerializer::class))
->attribute('guest_username', function (PostSerializer $serializer, Post $post) {
return $post->guest_username;
}),
(new Extend\ApiSerializer(PollSerializer::class))
->attributes(function (PollSerializer $serializer, Poll $poll): array {
return [
'guestVoteOption' => GuestManager::getPollVote($poll->id),
'canGuestVote' => $serializer->getActor()->can('votePolls'),
];
}),
(new Extend\ServiceProvider())
->register(Providers\PipeThroughPollVote::class)
->register(Providers\SaveDiscussionPost::class),
(new Extend\Event())
->listen(Saving::class, Listeners\SaveUser::class),
(new Extend\Policy())
->modelPolicy(Post::class, Access\PostPolicy::class),
];