Skip to content

Commit

Permalink
Allow "none" context for sort config (#2258)
Browse files Browse the repository at this point in the history
(fix #2257)
  • Loading branch information
jimsafley authored Feb 7, 2025
1 parent 68ca95b commit cdf44ce
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
22 changes: 22 additions & 0 deletions application/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,16 @@
'sort_order' => 'desc',
],
],
'none' => [
'items' => [
'sort_by' => 'created',
'sort_order' => 'desc',
],
'item_sets' => [
'sort_by' => 'created',
'sort_order' => 'desc',
],
],
],
'sort_defaults' => [
'admin' => [
Expand Down Expand Up @@ -746,6 +756,18 @@
'created' => 'Created', // @translate
],
],
'none' => [
'items' => [
'title' => 'Title', // @translate
'resource_class_label' => 'Resource class', // @translate
'created' => 'Created', // @translate
],
'item_sets' => [
'title' => 'Title', // @translate
'resource_class_label' => 'Resource class', // @translate
'created' => 'Created', // @translate
],
],
],
'page_templates' => [],
'block_templates' => [],
Expand Down
19 changes: 12 additions & 7 deletions application/src/Stdlib/Browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ public function getBrowseConfig(string $context, string $resourceType, ?int $use
// First, get the user-configured browse defaults, if any. Set the
// defaults from the config file if they're not configured or malformed.
$browseDefaultsSetting = sprintf('browse_defaults_%s_%s', $context, $resourceType);
$browseConfig = ('public' === $context)
? $this->getSiteSettings()->get($browseDefaultsSetting, null)
: $this->getUserSettings()->get($browseDefaultsSetting, null, $userId);
$browseConfig = null;
if ('public' === $context) {
$browseConfig = $this->getSiteSettings()->get($browseDefaultsSetting, null);
} elseif ('admin' === $context) {
$browseConfig = $this->getUserSettings()->get($browseDefaultsSetting, null, $userId);
}

if (!is_array($browseConfig)
|| !isset($browseConfig['sort_by'])
Expand Down Expand Up @@ -180,10 +183,12 @@ public function getColumnsData(string $context, string $resourceType, $userId =
// First, get the user-configured columns data, if any. Set the default
// if data is not configured or malformed.
$userColumnsSetting = sprintf('columns_%s_%s', $context, $resourceType);
$userColumnsData = ('public' === $context)
? $this->getSiteSettings()->get($userColumnsSetting, null)
: $this->getUserSettings()->get($userColumnsSetting, null, $userId);

$userColumnsData = null;
if ('public' === $context) {
$userColumnsData = $this->getSiteSettings()->get($userColumnsSetting, null);
} elseif ('admin' === $context) {
$userColumnsData = $this->getUserSettings()->get($userColumnsSetting, null, $userId);
}
if (!is_array($userColumnsData) || !$userColumnsData) {
$userColumnsData = $this->columnDefaults[$context][$resourceType] ?? [];
}
Expand Down
11 changes: 10 additions & 1 deletion application/view/common/advanced-search/sort.phtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?php
use Laminas\Form\Element;

$sortConfigContext = $this->status()->isAdminRequest() ? 'admin' : 'public';
// Set the sort config context.
if ($this->status()->isAdminRequest()) {
$sortConfigContext = 'admin';
} elseif ($this->status()->isSiteRequest()) {
$sortConfigContext = 'public';
} else {
$sortConfigContext = 'none';
}
// Set the sort config resource type.
switch ($resourceType) {
case 'itemSet':
$sortConfigResourceType = 'item_sets';
Expand All @@ -13,6 +21,7 @@ switch ($resourceType) {
default:
$sortConfigResourceType = 'items';
}
// Get the sort config according to context and resource type.
$sortConfig = $this->browse()->getBrowseService()->getSortConfig($sortConfigContext, $sortConfigResourceType);

$sortBy = new Element\Select('sort_by');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<form id="advanced-search" method="get" action="<?php echo $this->escapeHtml($this->url(null, ['action' => 'item-sets'], true)); ?>">
<?php echo $this->partial('common/advanced-search', ['query' => $this->params()->fromQuery(), 'resourceType' => 'item_set']); ?>
<?php echo $this->partial('common/advanced-search', ['query' => $this->params()->fromQuery(), 'resourceType' => 'itemSet']); ?>
<div class="advanced-search-actions">
<?php echo $this->hyperlink($this->translate('Reset'), $this->url(null, [], true), ['class' => 'button']); ?>
<input type="submit" name="submit" value="<?php echo $this->escapeHtml($this->translate('Search')); ?>">
Expand Down

0 comments on commit cdf44ce

Please sign in to comment.