Skip to content

Commit 9a8b63e

Browse files
committed
Merge pull request #1050 from FriendsOfSymfony/marydn-fixed
Apply defaultSortFieldName and defaultSortDirection pagination options
2 parents 3adfd9e + 33c4226 commit 9a8b63e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Subscriber/PaginateElasticaQuerySubscriber.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,19 @@ protected function setSorting(ItemsEvent $event)
6262
$options = $event->options;
6363
$sortField = $this->request->get($options['sortFieldParameterName']);
6464

65+
if (!$sortField && isset($options['defaultSortFieldName'])) {
66+
$sortField = $options['defaultSortFieldName'];
67+
}
68+
6569
if (!empty($sortField)) {
6670
// determine sort direction
6771
$dir = 'asc';
6872
$sortDirection = $this->request->get($options['sortDirectionParameterName']);
73+
74+
if (!$sortDirection && isset($options['defaultSortDirection'])) {
75+
$sortDirection = $options['defaultSortDirection'];
76+
}
77+
6978
if ('desc' === strtolower($sortDirection)) {
7079
$dir = 'desc';
7180
}

0 commit comments

Comments
 (0)