framework/extensions/nicknames/extend.php

57 lines
1.8 KiB
PHP
Raw Normal View History

2020-11-24 12:17:55 +08:00
<?php
/*
* This file is part of Flarum.
2020-11-24 12:17:55 +08:00
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
2020-11-24 12:17:55 +08:00
*/
namespace Flarum\Nicknames;
2020-12-01 09:48:10 +08:00
use Flarum\Api\Serializer\UserSerializer;
2020-11-24 12:17:55 +08:00
use Flarum\Extend;
use Flarum\Nicknames\Access\UserPolicy;
2020-11-24 12:17:55 +08:00
use Flarum\User\Event\Saving;
use Flarum\User\Search\UserSearcher;
use Flarum\User\User;
2020-12-01 09:48:10 +08:00
use Flarum\User\UserValidator;
2020-11-24 12:17:55 +08:00
return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js'),
2020-11-24 12:17:55 +08:00
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
2020-11-24 12:17:55 +08:00
new Extend\Locales(__DIR__.'/locale'),
2020-11-24 12:17:55 +08:00
(new Extend\User())
->displayNameDriver('nickname', NicknameDriver::class),
(new Extend\Event())
->listen(Saving::class, SaveNicknameToDatabase::class),
2020-11-24 12:17:55 +08:00
2020-12-01 09:48:10 +08:00
(new Extend\ApiSerializer(UserSerializer::class))
->attribute('canEditNickname', function (UserSerializer $serializer, User $user) {
return $serializer->getActor()->can('editNickname', $user);
2020-12-01 09:48:10 +08:00
}),
(new Extend\Settings())
->default('flarum-nicknames.set_on_registration', true)
->default('flarum-nicknames.min', 1)
->default('flarum-nicknames.max', 150)
->serializeToForum('displayNameDriver', 'display_name_driver', null, 'username')
->serializeToForum('setNicknameOnRegistration', 'flarum-nicknames.set_on_registration', 'boolval')
->serializeToForum('randomizeUsernameOnRegistration', 'flarum-nicknames.random_username', 'boolval'),
2020-12-01 09:48:10 +08:00
(new Extend\Validator(UserValidator::class))
->configure(AddNicknameValidation::class),
(new Extend\SimpleFlarumSearch(UserSearcher::class))
->setFullTextGambit(NicknameFullTextGambit::class),
(new Extend\Policy())
->modelPolicy(User::class, UserPolicy::class),
2020-11-24 12:17:55 +08:00
];