-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextend.php
More file actions
54 lines (45 loc) · 1.77 KB
/
extend.php
File metadata and controls
54 lines (45 loc) · 1.77 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
<?php
namespace Acpl\MyTags;
use Flarum\Api\Context;
use Flarum\Api\Endpoint;
use Flarum\Api\Resource;
use Flarum\Api\Schema;
use Flarum\Extend;
use Flarum\Tags\Tag;
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\ApiResource(Resource\ForumResource::class))
->fields(fn () => [
Schema\Relationship\ToMany::make('myFollowedTags')
->type('tags')
->includable()
->get(function ($model, Context $context) {
$actor = $context->getActor();
if ($actor->isGuest()) {
return [];
}
$followedTags = Tag::query()
->join('tag_user', function ($join) use ($actor) {
$join->on('tag_user.tag_id', '=', 'tags.id')
->where('tag_user.user_id', '=', $actor->id)
->whereIn('tag_user.subscription', ['follow', 'lurk']);
})
->select('tags.*')
->whereVisibleTo($actor)
->withStateFor($actor)
->get();
return $followedTags->all();
}),
])
->endpoint('show', function (Endpoint\Show $endpoint) {
return $endpoint->addDefaultInclude(['myFollowedTags']);
}),
(new Extend\Settings())
->serializeToForum('my-tags.enable-placeholder', 'acpl-my-tags.enable-placeholder')
->default('my-tags.enable-placeholder', false),
];