The newly added fields for sorting the list of discussions does not work when request page directly
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Feature Request
**Is your feature request related to a problem? Please describe.**
Add a new sort field to `ListDiscussionsController` (https://github.com/MichaelBelgium/flarum-discussion-views)
```
(new ApiController(ListDiscussionsController::class))
->addSortField('view_count'),
```
Frontend can extend sortMap by
```
extend(DiscussionListState.prototype, 'sortMap', function (map) {
if(app.forum.attribute('toggleFilter') == 1) {
map.popular = '-view_count';
map.unpopular = 'view_count';
}
});
```
So when we select new sort form index page, it can request `/api/discussions` with new sort field
But when we direct request by url `https://some-domain.com/?sort=popular`, the request will handle by `Flarum\Forum\Content\Index`
https://github.com/flarum/core/blob/b7cb1e8d368f3c2a349c9bcb5484ab1fffff6fab/src/Forum/Content/Index.php#L68-L82
method `getSortMap` hadcoded sort fields, so the new sort parameter will be ignored (also filter only accept `q`)
**Describe the solution you'd like**
A detailed description of your proposed solution. Include:
- custom sort and filter query parameters can pass to `$params` or can be extended when route to `Flarum\Forum\Content\Index`
**Justify why this feature belongs in Flarum's core, rather than in a third-party extension**
This code is hardcoded in core, extensions can not change it
**Describe alternatives you've considered**
Contributor guide
Assessment
This issue has not been assessed yet.