Skip to content
Snippets Groups Projects
Commit 95424d88 authored by Demian Katz's avatar Demian Katz
Browse files

Created handler-related lookup methods to simplify SearchTabs helper.

parent 144683e3
No related merge requests found
...@@ -157,6 +157,35 @@ abstract class Options implements TranslatorAwareInterface ...@@ -157,6 +157,35 @@ abstract class Options implements TranslatorAwareInterface
return $this->basicHandlers; 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. * Get default search handler.
* *
......
...@@ -137,28 +137,14 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper ...@@ -137,28 +137,14 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
protected function remapBasicSearch($activeOptions, $targetClass, $query, protected function remapBasicSearch($activeOptions, $targetClass, $query,
$handler $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: // Set up results object for URL building:
$results = $this->results->get($targetClass); $results = $this->results->get($targetClass);
$options = $results->getOptions(); $options = $results->getOptions();
// Find matching handler for new query (and use default if no match): // Find matching handler for new query (and use default if no match):
$targetHandler = false; $targetHandler = $options->getBasicHandlerForLabel(
foreach ($options->getBasicHandlers() as $id => $label) { $activeOptions->getLabelForBasicHandler($handler)
if ($label == $sourceLabel) { );
$targetHandler = $id;
}
}
if (!$targetHandler) {
$targetHandler = $options->getDefaultHandler();
}
// Build new URL: // Build new URL:
$results->getParams()->setBasicSearch($query, $targetHandler); $results->getParams()->setBasicSearch($query, $targetHandler);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment