From 1d27f62c15b569f4cd74a24fc38a636d34933f9f Mon Sep 17 00:00:00 2001 From: Ian Morland <16573496+imorland@users.noreply.github.com> Date: Mon, 4 Apr 2022 16:48:28 +0100 Subject: [PATCH] feat: add discussion sortmap to container binding (#3377) --- framework/core/src/Forum/Content/Index.php | 17 +---------------- .../core/src/Forum/ForumServiceProvider.php | 9 +++++++++ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/framework/core/src/Forum/Content/Index.php b/framework/core/src/Forum/Content/Index.php index 82ac0622e..3f02af7bb 100644 --- a/framework/core/src/Forum/Content/Index.php +++ b/framework/core/src/Forum/Content/Index.php @@ -70,7 +70,7 @@ class Index $page = max(1, intval(Arr::pull($queryParams, 'page'))); $filters = Arr::pull($queryParams, 'filter', []); - $sortMap = $this->getSortMap(); + $sortMap = resolve('flarum.forum.discussions.sortmap'); $params = [ 'sort' => $sort && isset($sortMap[$sort]) ? $sortMap[$sort] : '', @@ -96,21 +96,6 @@ class Index return $document; } - /** - * Get a map of sort query param values and their API sort params. - * - * @return array - */ - private function getSortMap() - { - return [ - 'latest' => '-lastPostedAt', - 'top' => '-commentCount', - 'newest' => '-createdAt', - 'oldest' => 'createdAt' - ]; - } - /** * Get the result of an API request to list discussions. * diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 3b0a952fe..57579e410 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -129,6 +129,15 @@ class ForumServiceProvider extends AbstractServiceProvider $this->container->bind('flarum.frontend.forum', function (Container $container) { return $container->make('flarum.frontend.factory')('forum'); }); + + $this->container->singleton('flarum.forum.discussions.sortmap', function () { + return [ + 'latest' => '-lastPostedAt', + 'top' => '-commentCount', + 'newest' => '-createdAt', + 'oldest' => 'createdAt' + ]; + }); } public function boot(Container $container, Dispatcher $events, Factory $view)