Skip to content

Commit

Permalink
Merge branch 'release-10.1' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Feb 20, 2025
2 parents 9002ef9 + ec55454 commit 1aee520
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 12 deletions.
4 changes: 3 additions & 1 deletion module/VuFind/src/VuFind/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public function editmemoryAction()
->rememberSearch($base . $query->getParams(false));
}

// Send the user back where they came from:
// Send the user back where they came from (but strip off the SID
// so we don't override the modified search with an older version):
$from = rtrim(preg_replace('/([?&])sid=\d+/', '$1', $from), '&?');
return $this->redirect()->toUrl($from);
}

Expand Down
5 changes: 5 additions & 0 deletions module/VuFind/src/VuFind/View/Helper/Root/SearchMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public function getLastSearchUrl(): ?string

$url .= $queryHelper->getParams(false);

// Make sure the URL stored in search memory stays in sync; if the stored URL has been manipulated
// through the EditMemory action and the user goes back to a page with a sid parameter, things can
// get into a bad state. Refreshing the value here ensures consistent behavior.
$this->memory->rememberSearch($url);

return $url;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1544,4 +1544,59 @@ public function testMultiSelectOnAdvancedSearch(bool $changeLanguage, bool $incl
$this->clickCss($page, '.js-apply-multi-facets-selection');
$this->assertCount(0, $page->findAll('css', '.facet.active'));
}

/**
* Test that filters applied during search show up on the record page and can be removed there.
*
* @return void
*/
public function testFilterClearingOnRecordPage(): void
{
// Start with a search with multiple filters applied:
$path = '/Search/Results'
. '?filter[]=building%3A"geo.mrc"'
. '&filter[]=format%3A"Book"'
. '&filter[]=author_facet%3A"Erickson%2C+Joette"&type=AllFields';
$session = $this->getMinkSession();
$session->visit($this->getVuFindUrl() . $path);
$page = $session->getPage();
$this->assertCount(3, $page->findAll('css', '.facet.active'));
$this->clickCss($page, '#result0 a.title');
$this->waitForPageLoad($page);

// Make sure the active filters show up:
$filterArea = $this->findCss($page, '.active-filters');
$filters = $filterArea->findAll('css', '.filter-value');
$this->assertCount(3, $filters);

// Save the current URL so we can return to it:
$urlWithSid = $session->getCurrentUrl();

// Remove the first filter:
$filters[0]->click();
$this->waitForPageLoad($page);

// There should now be fewer filters:
$filters = $filterArea->findAll('css', '.filter-value');
$this->assertCount(2, $filters);

// Now submit a new search:
$this->clickCss($page, '#searchForm .btn-primary');
$this->waitForPageLoad($page);
$this->assertCount(2, $page->findAll('css', '.facet.active'));

// Now go back to the original record page with the SID in the URL and
// confirm the return of the filters:
$session->visit($urlWithSid);
$filters = $filterArea->findAll('css', '.filter-value');
$this->assertCount(3, $filters);

// Remove the second filter:
$filters[1]->click();
$this->waitForPageLoad($page);

// There should now be fewer filters:
$filters = $filterArea->findAll('css', '.filter-value');
$this->assertCount(2, $filters);
}
}
6 changes: 3 additions & 3 deletions themes/bootstrap5/templates/search/filters.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<?php foreach ($this->checkboxFilters as $filter): ?>
<?php if ($filter['selected']): ?>
<?php
$removeLink = isset($urlQuery)
$removeLink = isset($urlQuery) && !$fromSearchMemory
? $urlQuery->removeFilter($filter['filter'])
: $this->searchMemory()->getEditLink(
$this->searchClassId,
Expand Down Expand Up @@ -90,7 +90,7 @@
<?=($index > 0 || 'NOT' === $value['operator']) ? $join : '' ?>
</span>
<?php
$removeLink = isset($this->urlQuery)
$removeLink = isset($this->urlQuery) && !$fromSearchMemory
? $urlQuery->removeFacet($value['field'], $value['value'], $value['operator'])
: $this->searchMemory()->getEditLink($this->searchClassId, 'removeFacet', $value);
?>
Expand Down Expand Up @@ -120,7 +120,7 @@
<?php
$resetLink = null;
if (!$onlyDefaultsApplied) {
$resetLink = isset($urlQuery)
$resetLink = isset($urlQuery) && !$fromSearchMemory
? $urlQuery->removeAllFilters()->resetDefaultFilters()
: $this->searchMemory()->getEditLink($this->searchClassId, 'removeAllFilters', 1);
}
Expand Down
25 changes: 17 additions & 8 deletions themes/bootstrap5/templates/search/searchbox.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
// Initialize from current search (if available and not explicitly overridden) or defaults:
if ($results = ($this->results ?? $this->searchMemory()->getCurrentSearch())) {
if ($this->results === null) {
$fromSearchMemory = true;
$results = $this->searchMemory()->getCurrentSearch();
} else {
$fromSearchMemory = false;
$results = $this->results;
}
if ($results) {
$params = $results->getParams();
$this->searchClassId = $params->getSearchClassId();
} else {
Expand Down Expand Up @@ -70,6 +77,7 @@
'checkboxFilters' => $showFilters ? $checkboxFilters : [],
'searchClassId' => $this->searchClassId,
'searchType' => $this->searchType,
'fromSearchMemory' => $fromSearchMemory,
]
);
?>
Expand Down Expand Up @@ -216,13 +224,14 @@
<?=$this->context($this)->renderInContext(
'search/filters.phtml',
[
'params' => $params ?? null,
'urlQuery' => isset($results) ? $results->getUrlQuery() : null,
'filterList' => $showFilters ? $filterList : [],
'checkboxFilters' => $showFilters ? $checkboxFilters : [],
'searchClassId' => $this->searchClassId,
'searchType' => $this->searchType,
]
'params' => $params ?? null,
'urlQuery' => isset($results) ? $results->getUrlQuery() : null,
'filterList' => $showFilters ? $filterList : [],
'checkboxFilters' => $showFilters ? $checkboxFilters : [],
'searchClassId' => $this->searchClassId,
'searchType' => $this->searchType,
'fromSearchMemory' => $fromSearchMemory,
]
);?>
</form>
<?php endif; ?>

0 comments on commit 1aee520

Please sign in to comment.