-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
59 lines (46 loc) · 1.78 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
<?php
namespace Flamarkt\PhoneNumber;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Extend;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\Event\Saving;
use Flarum\User\Filter\UserFilterer;
use Flarum\User\Search\UserSearcher;
use Flarum\User\User;
$extenders = [
(new Extend\Frontend('backoffice'))
->js(__DIR__ . '/js/dist/backoffice.js')
->css(__DIR__ . '/resources/less/common.less'),
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/resources/less/common.less'),
new Extend\Locales(__DIR__ . '/resources/locale'),
(new Extend\ApiSerializer(UserSerializer::class))
->attributes(UserAttributes::class),
(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(ForumAttributes::class),
(new Extend\Event())
->listen(Saving::class, Listeners\SaveUser::class),
(new Extend\Filter(UserFilterer::class))
->addFilter(Gambit\PhoneNumberGambit::class),
(new Extend\SimpleFlarumSearch(UserSearcher::class))
->addGambit(Gambit\PhoneNumberGambit::class),
(new Extend\Policy())
->modelPolicy(User::class, Access\UserPolicy::class),
];
if (class_exists(Scout::class)) {
$extenders[] = (new Scout(User::class))
->listenSaved(Event\PhoneNumberUpdated::class, function (Event\PhoneNumberUpdated $event) {
return $event->user;
})
->attributes(function (User $user): array {
if (!resolve(SettingsRepositoryInterface::class)->get('flamarkt-phone-number.searchable')) {
return [];
}
return [
'emailPhoneNumber' => $user->flamarkt_phone_number,
];
});
}
return $extenders;