Skip to content

Commit

Permalink
Add correct hidden filters to search links in records.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Oct 3, 2024
1 parent d81e86b commit 81f0872
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Search/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function getLastSearch(): ?\VuFind\Search\Base\Results
*
* @return ?\VuFind\Search\Base\Results
*/
protected function getSearchById(int $id): ?\VuFind\Search\Base\Results
public function getSearchById(int $id): ?\VuFind\Search\Base\Results
{
if (!array_key_exists($id, $this->searchCache)) {
$search = $this->searchService->getSearchByIdAndOwner($id, $this->sessionId, null);
Expand Down
52 changes: 45 additions & 7 deletions module/VuFind/src/VuFind/View/Helper/Root/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
use VuFind\Db\Service\DbServiceAwareTrait;
use VuFind\Db\Service\UserListServiceInterface;
use VuFind\Db\Service\UserResourceServiceInterface;
use VuFind\Search\Memory;
use VuFind\Search\UrlQueryHelper;
use VuFind\Tags\TagsService;

use function get_class;
Expand Down Expand Up @@ -72,6 +74,13 @@ class Record extends \Laminas\View\Helper\AbstractHelper implements DbServiceAwa
*/
protected $coverRouter = null;

/**
* Search memory
*
* @var Memory
*/
protected $searchMemory = null;

/**
* Record driver
*
Expand Down Expand Up @@ -102,6 +111,18 @@ public function setCoverRouter($router)
$this->coverRouter = $router;
}

/**
* Inject the search memory
*
* @param Memory $memory Search memory
*
* @return void
*/
public function setSearchMemory(Memory $memory): void
{
$this->searchMemory = $memory;
}

/**
* Render a template within a record driver folder.
*
Expand Down Expand Up @@ -460,13 +481,30 @@ public function getLink($type, $lookfor)

$prepend = (!str_contains($link, '?')) ? '?' : '&';

$link .= $this->getView()->plugin('searchTabs')
->getCurrentHiddenFilterParams(
$this->driver->getSearchBackendIdentifier(),
false,
$prepend
);
return $link;
$hiddenFilters = null;
// Try to get hidden filters for the current search:
if ($this->searchMemory) {
$searchId = $this->driver->getExtraDetail('searchId')
?? $this->getView()->plugin('searchMemory')->getLastSearchId();
if ($searchId && ($search = $this->searchMemory->getSearchById($searchId))) {
$filters = UrlQueryHelper::buildQueryString(
[
'hiddenFilters' => $search->getParams()->getHiddenFiltersAsQueryParams(),
]
);
$hiddenFilters = $filters ? $prepend . $filters : '';
}
}
// If we couldn't get hidden filters for the current search, use last filters:
if (null === $hiddenFilters) {
$hiddenFilters = $this->getView()->plugin('searchTabs')
->getCurrentHiddenFilterParams(
$this->driver->getSearchBackendIdentifier(),
false,
$prepend
);
}
return $link . $hiddenFilters;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __invoke(
$config = $container->get(\VuFind\Config\PluginManager::class)->get('config');
$helper = new $requestedName($container->get(TagsService::class), $config);
$helper->setCoverRouter($container->get(\VuFind\Cover\Router::class));
$helper->setSearchMemory($container->get(\VuFind\Search\Memory::class));
return $helper;
}
}

0 comments on commit 81f0872

Please sign in to comment.