Skip to content

Commit

Permalink
Fix sort_by_default handling (fix #2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley committed Dec 1, 2023
1 parent 183904e commit 4e05537
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
1 change: 0 additions & 1 deletion application/src/Mvc/Controller/Plugin/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function __invoke($totalCount, $currentPage = null, $perPage = null, $par
{
// Fetch variables from the query if none provided.
$query = $this->getController()->getRequest()->getQuery();
$query->set('sort_by', (!isset($query['sort_by_default']) && isset($query['sort_by'])) ? $query['sort_by'] : '');
$currentPage = $currentPage ?: $query->get('page', $currentPage);
$perPage = $perPage ?: $query->get('per_page', $perPage);

Expand Down
5 changes: 3 additions & 2 deletions application/src/View/Helper/Browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ public function renderSortSelector($resourceTypeOrSortConfig) : string
return '';
}
$query = $view->params()->fromQuery();
if (isset($query['fulltext_search']) && '' !== trim($query['fulltext_search'])) {
$isFulltextSearch = (isset($query['fulltext_search']) && '' !== trim($query['fulltext_search']));
if ($isFulltextSearch) {
$sortConfig[''] = 'Relevance'; // @translate
}
$args = [
'sortConfig' => $sortConfig,
'sortByQuery' => isset($query['sort_by_default']) ? '' : $view->params()->fromQuery('sort_by'),
'sortByQuery' => (isset($query['sort_by_default']) && $isFulltextSearch) ? '' : $view->params()->fromQuery('sort_by'),
'sortOrderQuery' => $view->params()->fromQuery('sort_order'),
];
$args = $view->trigger('view.sort-selector', $args, true);
Expand Down
1 change: 1 addition & 0 deletions application/src/View/Helper/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected function getUrl($page)
{
$query = $this->getView()->params()->fromQuery();
$query['page'] = (int) $page;
unset($query['sort_by_default']);
$options = ['query' => $query];
if (is_string($this->fragment)) {
$options['fragment'] = $this->fragment;
Expand Down
2 changes: 1 addition & 1 deletion application/view/common/pagination.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $translate = $this->plugin('translate');
<nav class="pagination" role="navigation">
<?php if ($totalCount): ?>
<form method="GET" action="">
<?php echo $this->queryToHiddenInputs(['page']); ?>
<?php echo $this->queryToHiddenInputs(['page', 'sort_by_default']); ?>
<input type="text" name="page" class="page-input-top" value="<?php echo $currentPage; ?>" size="4" <?php echo ($pageCount == 1) ? 'readonly' : ''; ?> aria-label="<?php echo $translate('Page'); ?>">
<span class="page-count"><?php echo sprintf($translate('of %s'), $pageCount); ?></span>
</form>
Expand Down
2 changes: 1 addition & 1 deletion application/view/common/sort-selector.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
?>
<form class="sorting" action="">
<?php echo $this->queryToHiddenInputs(['sort_by', 'sort_order']); ?>
<?php echo $this->queryToHiddenInputs(['sort_by', 'sort_order', 'sort_by_default']); ?>
<select name="sort_by" aria-label="<?php echo $translate('Sort by'); ?>">
<?php foreach($sortConfig as $sortBy => $label): ?>
<option value="<?php echo $escape($sortBy); ?>"<?php echo ($sortByQuery === $sortBy) ? ' selected' : ''; ?>><?php echo $escape($label); ?></option>
Expand Down

0 comments on commit 4e05537

Please sign in to comment.