-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathextend.php
More file actions
84 lines (69 loc) · 3.13 KB
/
extend.php
File metadata and controls
84 lines (69 loc) · 3.13 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Acpl\MobileTab;
use Acpl\MobileTab\Api\Resource\CustomTabItemResource;
use Flarum\Api\Endpoint;
use Flarum\Api\Resource;
use Flarum\Api\Schema;
use Flarum\Extend;
use Flarum\Frontend\Document;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Support\Str;
use Psr\Log\LoggerInterface;
return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/less/admin.less'),
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/less/forum.less'),
new Extend\Locales(__DIR__.'/locale'),
(new Extend\Settings)
->default('acpl-mobile-tab.items', ['home', 'tags', 'notifications', 'session'])
->serializeToForum('acplMobileTabItems', 'acpl-mobile-tab.items', function ($value) {
if (is_string($value)) {
if (! Str::isJson($value)) {
$logger = resolve(LoggerInterface::class);
$logger->error('Invalid JSON in acpl-mobile-tab.items setting');
return [];
}
return json_decode($value);
}
return $value;
})
->default('acpl-mobile-tab.hide_on_scroll', true)
->serializeToForum('acplMobileTabHideOnScroll', 'acpl-mobile-tab.hide_on_scroll', 'boolval')
->default('acpl-mobile-tab.scroll_threshold', 80)
->serializeToForum('acplMobileTabScrollThreshold', 'acpl-mobile-tab.scroll_threshold', 'intval'),
(new Extend\Frontend('forum'))
->content(function (Document $document) {
$document->meta['viewport'] = "{$document->meta['viewport']}, viewport-fit=cover";
}),
new Extend\ApiResource(CustomTabItemResource::class),
(new Extend\ApiResource(Resource\ForumResource::class))
->fields(fn () => [
Schema\Relationship\ToMany::make('custom-tab-items')
->includable()
->get(function () {
$settings = resolve(SettingsRepositoryInterface::class);
$activeItems = $settings->get('acpl-mobile-tab.items');
if (is_string($activeItems)) {
if (! Str::isJson($activeItems)) {
$logger = resolve(LoggerInterface::class);
$logger->error('Invalid JSON in acpl-mobile-tab.items setting');
return [];
}
$activeItems = json_decode($activeItems);
}
$customActiveItemIds = collect($activeItems)
->filter(fn ($item) => str_starts_with($item, 'custom-'))
->map(fn ($item) => str_replace('custom-', '', $item));
if ($customActiveItemIds->isEmpty()) {
return [];
}
return CustomTabItem::query()->whereIn('id', $customActiveItemIds)->get()->all();
})
])
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint) {
return $endpoint->addDefaultInclude(['custom-tab-items']);
}),
];