From df1ea7a5a59913743a3135387640cbbc1a162303 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Wed, 8 Jan 2025 15:44:38 -0500 Subject: [PATCH] Combined jump links: configurable linking modes --- config/vufind/combined.ini | 5 +++ .../VuFindTest/Mink/CombinedSearchTest.php | 32 ++++++++++++++++++- .../templates/combined/jump-links.phtml | 18 ++++++++++- .../templates/combined/results-list.phtml | 13 +++++--- .../templates/combined/results.phtml | 10 +++++- .../templates/combined/jump-links.phtml | 18 ++++++++++- .../templates/combined/results-list.phtml | 13 +++++--- .../templates/combined/results.phtml | 10 +++++- 8 files changed, 106 insertions(+), 13 deletions(-) diff --git a/config/vufind/combined.ini b/config/vufind/combined.ini index 2731d258d40..119b00a5934 100644 --- a/config/vufind/combined.ini +++ b/config/vufind/combined.ini @@ -99,6 +99,11 @@ columns = 3 stack_placement = distributed ; Jump links appear above the search results and link to each result module ;jump_links = true +; If jump_links is true, this setting can control what types of links are used: +; 'anchor' will create anchor links that jump to the matching column on the page +; 'link' will link directly to the expanded search results +; The default is 'anchor' +;jump_links_mode = anchor [Solr] label = Catalog diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php index d435e635af5..2bc9e5711ba 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CombinedSearchTest.php @@ -239,16 +239,34 @@ public function testCombinedSearchResultsMixedAjax(): void $this->assertResultsForDefaultQuery($page); } + /** + * Data provider for testJumpMenu() + * + * @return array[] + */ + public static function jumpMenuProvider(): array + { + return [ + 'anchor mode' => ['anchor'], + 'link mode' => ['link'], + ]; + } + /** * Test that the jump menu can be enabled. * + * @param string $linkMode Linking mode to activate + * * @return void + * + * @dataProvider jumpMenuProvider */ - public function testJumpMenu(): void + public function testJumpMenu(string $linkMode): void { $config = $this->getCombinedIniOverrides(); $config['Solr:one']['ajax'] = true; // use mixed AJAX mode for more thorough test $config['Layout']['jump_links'] = true; + $config['Layout']['jump_links_mode'] = $linkMode; $this->changeConfigs( ['combined' => $config], ['combined'] @@ -262,6 +280,18 @@ public function testJumpMenu(): void $expectedContent, $this->findCssAndGetText($page, '.combined-jump-links') ); + $firstLink = $this->findCss($page, '.combined-jump-links a')->getAttribute('href'); + $secondLink = $this->findCss($page, '.combined-jump-links a', index: 1)->getAttribute('href'); + $expectedFirstLink = $linkMode === 'anchor' + ? '#combined_Solr____one' + : '/Search/Results?hiddenFilters%5B%5D=building%3A%22journals.mrc%22&lookfor=id%3A%22testsample1%22' + . '+OR+id%3A%22theplus%2Bandtheminus-%22&type=AllFields'; + $expectedSecondLink = $linkMode === 'anchor' + ? '#combined_Solr____two' + : '/Search/Results?hiddenFilters%5B%5D=building%3A%22weird_ids.mrc%22&lookfor=id%3A%22testsample1%22' + . '+OR+id%3A%22theplus%2Bandtheminus-%22&type=AllFields'; + $this->assertStringEndsWith($expectedFirstLink, $firstLink); + $this->assertStringEndsWith($expectedSecondLink, $secondLink); } /** diff --git a/themes/bootstrap3/templates/combined/jump-links.phtml b/themes/bootstrap3/templates/combined/jump-links.phtml index 6567ce948a0..13bfc5c58fd 100644 --- a/themes/bootstrap3/templates/combined/jump-links.phtml +++ b/themes/bootstrap3/templates/combined/jump-links.phtml @@ -2,8 +2,24 @@ translate('combined_jump_links_intro')?> diff --git a/themes/bootstrap3/templates/combined/results-list.phtml b/themes/bootstrap3/templates/combined/results-list.phtml index 48512e34f08..cf82ca53f3c 100644 --- a/themes/bootstrap3/templates/combined/results-list.phtml +++ b/themes/bootstrap3/templates/combined/results-list.phtml @@ -45,19 +45,24 @@ // Update result counts in jump links $classId = $this->escapeHtml($domId ?? 'combined_' . $searchClassId); + $jsMoreUrl = $this->escapeJs(html_entity_decode($moreUrl)); $countsJs = << - render('combined/jump-links.phtml', ['combinedResults' => $this->combinedResults])?> + render( + 'combined/jump-links.phtml', + [ + 'combinedResults' => $this->combinedResults, + 'mode' => $config['Layout']['jump_links_mode'] ?? 'anchor', + ] + ) + ?>
context($this)->renderInContext('search/bulk-action-buttons.phtml', ['idPrefix' => ''])?> diff --git a/themes/bootstrap5/templates/combined/jump-links.phtml b/themes/bootstrap5/templates/combined/jump-links.phtml index 6567ce948a0..13bfc5c58fd 100644 --- a/themes/bootstrap5/templates/combined/jump-links.phtml +++ b/themes/bootstrap5/templates/combined/jump-links.phtml @@ -2,8 +2,24 @@ translate('combined_jump_links_intro')?>
    + results ?? null) + && !($results instanceof \VuFind\Search\Combined\Results) + ) { + $params = $results->getParams(); + $lookfor = $results->getUrlQuery()->isQuerySuppressed() ? '' : $params->getDisplayQuery(); + $href = $this->url($params->getOptions()->getSearchAction()) . $results->getUrlQuery()->setPage(1)->setLimit($params->getOptions()->getDefaultLimit()); + } else { + $href = '#' . $section['domId']; + } + ?>
  • - transEsc($section['label']) ?> + transEsc($section['label']) ?>
diff --git a/themes/bootstrap5/templates/combined/results-list.phtml b/themes/bootstrap5/templates/combined/results-list.phtml index 48512e34f08..cf82ca53f3c 100644 --- a/themes/bootstrap5/templates/combined/results-list.phtml +++ b/themes/bootstrap5/templates/combined/results-list.phtml @@ -45,19 +45,24 @@ // Update result counts in jump links $classId = $this->escapeHtml($domId ?? 'combined_' . $searchClassId); + $jsMoreUrl = $this->escapeJs(html_entity_decode($moreUrl)); $countsJs = << - render('combined/jump-links.phtml', ['combinedResults' => $this->combinedResults])?> + render( + 'combined/jump-links.phtml', + [ + 'combinedResults' => $this->combinedResults, + 'mode' => $config['Layout']['jump_links_mode'] ?? 'anchor', + ] + ) + ?> context($this)->renderInContext('search/bulk-action-buttons.phtml', ['idPrefix' => ''])?>