Repository navigation
Expand file tree
/
Copy pathextend.php
More file actions
67 lines (54 loc) · 2.25 KB
/
Copy pathextend.php
File metadata and controls
67 lines (54 loc) · 2.25 KB
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
65
66
67
<?php
namespace FFans\CommunityNotes;
use FFans\CommunityNotes\Settings\ScoringSettings;
use Flarum\Api\Resource\DiscussionResource;
use Flarum\Api\Resource\ForumResource;
use Flarum\Api\Resource\PostResource;
use Flarum\Extend;
use Flarum\Post\Post;
use Flarum\Settings\Event\Saving;
return [
// Assets
(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')
->css(__DIR__ . '/less/admin.less'),
new Extend\Locales(__DIR__ . '/locale'),
// Settings
(new Extend\Settings())
->default(ScoringSettings::MIN_RATINGS, 5)
->default(ScoringSettings::HELPFUL_THRESHOLD, 80)
->default(ScoringSettings::NOT_HELPFUL_THRESHOLD, 20),
// ServiceProvider
(new Extend\ServiceProvider())
->register(Provider\ScoringServiceProvider::class),
// Policy
(new Extend\Policy())
->modelPolicy(Model\CommunityNote::class, Access\CommunityNotePolicy::class),
// Event
(new Extend\Event())
->listen(Saving::class, Listener\ValidateScoringSettings::class)
->subscribe(Listener\RescoreNotesWhenSettingsSaved::class),
// Ext Model
// Core Model
(new Extend\Model(Post::class))
->relationship('communityNote', Api\PublicCommunityNoteRelation::class)
->hasMany('communityNotes', Model\CommunityNote::class, 'post_id'),
// Routes
(new Extend\Frontend('forum'))
->route('/community-notes', 'communityNotes')
->route('/community-notes/posts/{id}', 'communityNotesPost'),
// ApiResources
new Extend\ApiResource(Api\Resource\CommunityNoteResource::class),
// Core ApiResources
(new Extend\ApiResource(PostResource::class))
->fields(Api\CommunityNotePostFields::class)
->endpoint(['index', 'show', 'create', 'update'], fn($endpoint) => $endpoint->addDefaultInclude(['communityNote'])),
(new Extend\ApiResource(DiscussionResource::class))
->endpoint('show', fn($endpoint) => $endpoint->addDefaultInclude(['firstPost.communityNote', 'lastPost.communityNote'])),
(new Extend\ApiResource(ForumResource::class))
->fields(Api\CommunityNoteForumFields::class),
// GDPR
];