extend.php
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Api\Event\WillGetData;
use Flarum\Extend;
return [
new Extend\Compat(function (Dispatcher $events) {
$events->listen(WillGetData::class, function (WillGetData $event) {
if ($event->isController(ListDiscussionsController::class) ) {
$sort = $_GET['sort'];
if(!$sort) {
$event->setSort(['createdAt'=>'desc']);
}
}
});
];
forum/index.js
import DiscussionList from 'flarum/components/DiscussionList';
override(DiscussionList.prototype,'sortMap',function (original) {
const map = {};
if (this.props.params.q) {
map.relevance = '';
}
map.newest = '-createdAt';
map.latest = '-lastPostedAt';
map.top = '-commentCount';
map.oldest = 'createdAt';
return map;
});
solve!