framework/extensions/flags/extend.php

50 lines
1.5 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Api\Event\Serializing;
use Flarum\Extend;
use Flarum\Flags\Api\Controller\CreateFlagController;
use Flarum\Flags\Api\Controller\DeleteFlagsController;
use Flarum\Flags\Api\Controller\ListFlagsController;
use Flarum\Flags\Flag;
use Flarum\Flags\Listener;
use Flarum\Forum\Content\AssertRegistered;
use Flarum\Post\Post;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;
return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/less/forum.less')
->route('/flags', 'flags', AssertRegistered::class),
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
(new Extend\Routes('api'))
->get('/flags', 'flags.index', ListFlagsController::class)
->post('/flags', 'flags.create', CreateFlagController::class)
->delete('/posts/{id}/flags', 'flags.delete', DeleteFlagsController::class),
(new Extend\Model(User::class))
->dateAttribute('read_flags_at'),
(new Extend\Model(Post::class))
->hasMany('flags', Flag::class, 'post_id'),
new Extend\Locales(__DIR__.'/locale'),
function (Dispatcher $events) {
$events->listen(Serializing::class, Listener\AddFlagsApiAttributes::class);
$events->subscribe(Listener\AddPostFlagsRelationship::class);
},
];