mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 22:43:41 +08:00
4b126d9f4c
* refactor: move gambits to frontend (#3885) * refactor: move gambits to frontend * test: GambitManager * refactor: merge filterer and searcher concepts (#3892) * chore: drop remaining backend regex gambits * refactor: merge filterer & searcher concept * refactor: adapt extenders * refactor: no longer need to push gambits to `q` * refactor: filters to gambits * refactor: drop shred `Query` namespace * chore: cleanup * chore: leftover gambit references on the backend (#3894) * chore: leftover gambit references on the backend * chore: namespace * feat: search driver backend extension API (#3902) * feat: first iteration of search drivers * feat: indexer API & tweaks * feat: changes after POC driver * fix: properly fire custom observables * chore: remove debugging code * fix: phpstan * fix: custom eloquent events * chore: drop POC usage * test: indexer extender API * fix: extension searcher fails without filters * fix: phpstan * fix: frontend created gambit * feat: advanced page and localized driver settings (#3905) * feat: allow getting total search results and replacing filters (#3906) * feat: allow accessing total search results * feat: allow replacing filters * chore: phpstan
61 lines
2.2 KiB
PHP
61 lines
2.2 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\Controller\ListDiscussionsController;
|
|
use Flarum\Api\Serializer\DiscussionSerializer;
|
|
use Flarum\Discussion\Discussion;
|
|
use Flarum\Discussion\Event\Saving;
|
|
use Flarum\Discussion\Search\DiscussionSearcher;
|
|
use Flarum\Extend;
|
|
use Flarum\Search\Database\DatabaseSearchDriver;
|
|
use Flarum\Sticky\Event\DiscussionWasStickied;
|
|
use Flarum\Sticky\Event\DiscussionWasUnstickied;
|
|
use Flarum\Sticky\Listener;
|
|
use Flarum\Sticky\Listener\SaveStickyToDatabase;
|
|
use Flarum\Sticky\PinStickiedDiscussionsToTop;
|
|
use Flarum\Sticky\Post\DiscussionStickiedPost;
|
|
use Flarum\Sticky\Query\StickyFilter;
|
|
|
|
return [
|
|
(new Extend\Frontend('forum'))
|
|
->js(__DIR__.'/js/dist/forum.js')
|
|
->css(__DIR__.'/less/forum.less'),
|
|
|
|
(new Extend\Model(Discussion::class))
|
|
->cast('is_sticky', 'bool'),
|
|
|
|
(new Extend\Post())
|
|
->type(DiscussionStickiedPost::class),
|
|
|
|
(new Extend\ApiSerializer(DiscussionSerializer::class))
|
|
->attribute('isSticky', function (DiscussionSerializer $serializer, Discussion $discussion) {
|
|
return (bool) $discussion->is_sticky;
|
|
})
|
|
->attribute('canSticky', function (DiscussionSerializer $serializer, $discussion) {
|
|
return (bool) $serializer->getActor()->can('sticky', $discussion);
|
|
}),
|
|
|
|
(new Extend\ApiController(ListDiscussionsController::class))
|
|
->addInclude('firstPost'),
|
|
|
|
(new Extend\Frontend('admin'))
|
|
->js(__DIR__.'/js/dist/admin.js'),
|
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
|
|
|
(new Extend\Event())
|
|
->listen(Saving::class, SaveStickyToDatabase::class)
|
|
->listen(DiscussionWasStickied::class, [Listener\CreatePostWhenDiscussionIsStickied::class, 'whenDiscussionWasStickied'])
|
|
->listen(DiscussionWasUnstickied::class, [Listener\CreatePostWhenDiscussionIsStickied::class, 'whenDiscussionWasUnstickied']),
|
|
|
|
(new Extend\SearchDriver(DatabaseSearchDriver::class))
|
|
->addFilter(DiscussionSearcher::class, StickyFilter::class)
|
|
->addMutator(DiscussionSearcher::class, PinStickiedDiscussionsToTop::class),
|
|
];
|