diff --git a/module/VuFind/src/VuFind/Search/Base/Options.php b/module/VuFind/src/VuFind/Search/Base/Options.php index be2f7f6b2cf98f9d49e5f61d72b879bed375ee83..aaa7c5593dae6b83529773556dc27a3501554331 100644 --- a/module/VuFind/src/VuFind/Search/Base/Options.php +++ b/module/VuFind/src/VuFind/Search/Base/Options.php @@ -157,6 +157,35 @@ abstract class Options implements TranslatorAwareInterface return $this->basicHandlers; } + /** + * Given a label from the configuration file, return the name of the matching + * basic handler; return the default handler if no match is found. + * + * @param string $label Label to search for + * + * @return string + */ + public function getBasicHandlerForLabel($label) + { + $targetHandler = false; + foreach ($this->getBasicHandlers() as $id => $currentLabel) { + if ($currentLabel == $label) { + return $id; + } + } + return $this->getDefaultHandler(); + } + + /** + * Given a basic handler name, return the corresponding label (or false + * if none found): + */ + public function getLabelForBasicHandler($handler) + { + return isset($this->basicHandlers[$handler]) + ? $this->basicHandlers[$handler] : false; + } + /** * Get default search handler. * diff --git a/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php b/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php index 2b99e7c83241fe61ff32afe0fccb3ae7f1de3ae9..bd0e366725d665a1217d418937355cf5d24e18cf 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/SearchTabs.php @@ -137,28 +137,14 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper protected function remapBasicSearch($activeOptions, $targetClass, $query, $handler ) { - // Get label for source handler: - $sourceLabel = false; - foreach ($activeOptions->getBasicHandlers() as $id => $label) { - if ($handler == $id) { - $sourceLabel = $label; - } - } - // Set up results object for URL building: $results = $this->results->get($targetClass); $options = $results->getOptions(); // Find matching handler for new query (and use default if no match): - $targetHandler = false; - foreach ($options->getBasicHandlers() as $id => $label) { - if ($label == $sourceLabel) { - $targetHandler = $id; - } - } - if (!$targetHandler) { - $targetHandler = $options->getDefaultHandler(); - } + $targetHandler = $options->getBasicHandlerForLabel( + $activeOptions->getLabelForBasicHandler($handler) + ); // Build new URL: $results->getParams()->setBasicSearch($query, $targetHandler);