Skip to content

Commit 1d27f62

Browse files
authored
feat: add discussion sortmap to container binding (#3377)
1 parent 9d9594a commit 1d27f62

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

framework/core/src/Forum/Content/Index.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __invoke(Document $document, Request $request)
7070
$page = max(1, intval(Arr::pull($queryParams, 'page')));
7171
$filters = Arr::pull($queryParams, 'filter', []);
7272

73-
$sortMap = $this->getSortMap();
73+
$sortMap = resolve('flarum.forum.discussions.sortmap');
7474

7575
$params = [
7676
'sort' => $sort && isset($sortMap[$sort]) ? $sortMap[$sort] : '',
@@ -96,21 +96,6 @@ public function __invoke(Document $document, Request $request)
9696
return $document;
9797
}
9898

99-
/**
100-
* Get a map of sort query param values and their API sort params.
101-
*
102-
* @return array
103-
*/
104-
private function getSortMap()
105-
{
106-
return [
107-
'latest' => '-lastPostedAt',
108-
'top' => '-commentCount',
109-
'newest' => '-createdAt',
110-
'oldest' => 'createdAt'
111-
];
112-
}
113-
11499
/**
115100
* Get the result of an API request to list discussions.
116101
*

framework/core/src/Forum/ForumServiceProvider.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ public function register()
129129
$this->container->bind('flarum.frontend.forum', function (Container $container) {
130130
return $container->make('flarum.frontend.factory')('forum');
131131
});
132+
133+
$this->container->singleton('flarum.forum.discussions.sortmap', function () {
134+
return [
135+
'latest' => '-lastPostedAt',
136+
'top' => '-commentCount',
137+
'newest' => '-createdAt',
138+
'oldest' => 'createdAt'
139+
];
140+
});
132141
}
133142

134143
public function boot(Container $container, Dispatcher $events, Factory $view)

0 commit comments

Comments
 (0)