diff --git a/module/finc/src/finc/Controller/RecordsController.php b/module/finc/src/finc/Controller/RecordsController.php index 3238f7138125a6f0120c2fae2d6d3ce34f23af51..b1c1497d11fcd2194d47fd3856a883a566c92cd4 100644 --- a/module/finc/src/finc/Controller/RecordsController.php +++ b/module/finc/src/finc/Controller/RecordsController.php @@ -30,6 +30,7 @@ namespace finc\Controller; use VuFind\Controller\RecordsController as BaseController; +use VuFind\RecordDriver\AbstractBase; /** * Records Controller @@ -49,19 +50,41 @@ class RecordsController extends BaseController */ protected $suppressJump; + /** + * Driver for each single record + * + * @var array of AbstractBase with key = params and value = driver + */ + protected $driverList; + /** * Bypass the single record handling of the parent method when printing * @return bool|mixed|\VuFind\Controller\ViewModel|\Laminas\View\Model\ViewModel */ public function homeAction() { - $this->suppressJump = false; - if ($this->params()->fromQuery('print')) { - $this->suppressJump = true; - return $this->resultsAction(); + // If there is only one record, vufind RecordsController redirects + // to record controller - but we (finc) do not want that in some cases + if (count(($params = $this->params()->fromQuery('id', []))) === 1) { + // refs #17990 avoid error for FincMissing after Vufind redirect + if ($this->params()->fromQuery('print') + && $this->getDriver($params) instanceof \finc\RecordDriver\FincMissing + ) { + $this->suppressJump = true; + return $this->resultsAction(); + } + + // refs #21613 always use collections view if collections are activated (de_15) + $config = $this->serviceLocator->get('VuFind\Config\PluginManager') + ->get('config'); + if (($config->Collections->collections ?? false) + && $this->getDriver($params) instanceof \finc\RecordDriver\SolrDico + ) { + return $this->resultsAction(); + } } - return $this->resultsAction(); + return parent::homeAction(); } /** @@ -109,4 +132,43 @@ class RecordsController extends BaseController ->getTabRouteDetails($recordList[$jumpto - 1]); return $this->redirect()->toRoute($details['route'], $details['params']); } + + /** + * Get driver for param + * + * @param string $param query id + * + * @return AbstractBase + */ + protected function getDriver($param): AbstractBase + { + $param = is_array($param) ? $param[0] : $param; + if (!isset($this->driverList[$param])) { + [$source, $id] = $this->extractSourceAndId($param); + $this->driverList[$param] = $this->getRecordLoader() + ->load($id, $source, true); + } + return $this->driverList[$param]; + } + + /** + * Get source and id from string + * Copied from \VuFind\Record\Router + * + * @param string $params query id + * + * @return array + */ + protected function extractSourceAndId($params) + { + $parts = explode('|', $params, 2); + if (count($parts) < 2) { + $source = DEFAULT_SEARCH_BACKEND; + $id = $parts[0]; + } else { + $source = $parts[0]; + $id = $parts[1]; + } + return [$source, $id]; + } }