diff --git a/config/vufind/Search2.ini b/config/vufind/Search2.ini index abae94983bfabffd9f453918d96d2d8f4575d151..e1ef3905d43bdd06d2fd6ffc57873f71c0f9da1e 100644 --- a/config/vufind/Search2.ini +++ b/config/vufind/Search2.ini @@ -32,6 +32,7 @@ skip_numeric = true [Record] next_prev_navigation = false +related[] = Similar ; ---------- searches.ini settings ---------- diff --git a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php index c0e2602105a900d7e6ef0f517cc1fad26db923ad..cd0d9da2f0799937ec91f636a67922c9bc937dba 100644 --- a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php +++ b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php @@ -296,41 +296,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, return $this->sourceIdentifier; } - /** - * Return an array of related record suggestion objects (implementing the - * \VuFind\Related\RelatedInterface) based on the current record. - * - * @param \VuFind\Related\PluginManager $factory Related module plugin factory - * @param array $types Array of relationship types to - * load; each entry should be a service name (i.e. 'Similar' or 'Editions') - * optionally followed by a colon-separated list of parameters to pass to the - * constructor. If the parameter is set to null instead of an array, default - * settings will be loaded from config.ini. - * - * @return array - */ - public function getRelated(\VuFind\Related\PluginManager $factory, $types = null) - { - if (null === $types) { - $types = isset($this->recordConfig->Record->related) ? - $this->recordConfig->Record->related : []; - } - $retVal = []; - foreach ($types as $current) { - $parts = explode(':', $current); - $type = $parts[0]; - $params = $parts[1] ?? null; - if ($factory->has($type)) { - $plugin = $factory->get($type); - $plugin->init($params, $this); - $retVal[] = $plugin; - } else { - throw new \Exception("Related module {$type} does not exist."); - } - } - return $retVal; - } - /** * Returns true if the record supports real-time AJAX status lookups. * diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Related.php b/module/VuFind/src/VuFind/View/Helper/Root/Related.php index a1c8203b6fe0724d3d1e268929d196bc6f889f25..eff50addd4a3b2860f0eafcf725ba24ded72b82b 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Related.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Related.php @@ -27,6 +27,10 @@ */ namespace VuFind\View\Helper\Root; +use VuFind\Config\PluginManager as ConfigManager; +use VuFind\Related\PluginManager as RelatedManager; +use VuFind\Search\Options\PluginManager as OptionsManager; + /** * Related records view helper * @@ -38,10 +42,24 @@ namespace VuFind\View\Helper\Root; */ class Related extends AbstractClassBasedTemplateRenderer { + /** + * Config manager + * + * @var ConfigManager + */ + protected $configManager; + + /** + * Plugin manager for search options. + * + * @var OptionsManager + */ + protected $optionsManager; + /** * Plugin manager for related record modules. * - * @var \VuFind\Related\PluginManager + * @var RelatedManager */ protected $pluginManager; @@ -51,9 +69,31 @@ class Related extends AbstractClassBasedTemplateRenderer * @param \VuFind\Related\PluginManager $pluginManager Plugin manager for related * record modules. */ - public function __construct(\VuFind\Related\PluginManager $pluginManager) - { + public function __construct(RelatedManager $pluginManager, + ConfigManager $cm, OptionsManager $om + ) { $this->pluginManager = $pluginManager; + $this->configManager = $cm; + $this->optionsManager = $om; + } + + /** + * Given a record source ID, return the appropriate related record configuration. + * + * @param string $source Source identifier + * + * @return array + */ + protected function getConfigForSource($source) + { + $options = $this->optionsManager->get($source); + $configName = $options->getSearchIni(); + // Special case -- default Solr stores [Record] section in config.ini + if ($configName === 'searches') { + $configName = 'config'; + } + $config = $this->configManager->get($configName); + return $config->Record->related ?? []; } /** @@ -65,7 +105,21 @@ class Related extends AbstractClassBasedTemplateRenderer */ public function getList(\VuFind\RecordDriver\AbstractBase $driver) { - return $driver->getRelated($this->pluginManager); + $retVal = []; + $config = $this->getConfigForSource($driver->getSourceIdentifier()); + foreach ($config as $current) { + $parts = explode(':', $current); + $type = $parts[0]; + $params = $parts[1] ?? null; + if ($this->pluginManager->has($type)) { + $plugin = $this->pluginManager->get($type); + $plugin->init($params, $driver); + $retVal[] = $plugin; + } else { + throw new \Exception("Related module {$type} does not exist."); + } + } + return $retVal; } /** diff --git a/module/VuFind/src/VuFind/View/Helper/Root/RelatedFactory.php b/module/VuFind/src/VuFind/View/Helper/Root/RelatedFactory.php index 33146f1e3d5e391a45aa32a19dcc731766db060b..bb65c7ee17b2669881df3589b98f19f067fa4b87 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/RelatedFactory.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/RelatedFactory.php @@ -61,6 +61,10 @@ class RelatedFactory implements FactoryInterface if (!empty($options)) { throw new \Exception('Unexpected options sent to factory.'); } - return new $requestedName($container->get('VuFind\Related\PluginManager')); + return new $requestedName( + $container->get('VuFind\Related\PluginManager'), + $container->get('VuFind\Config\PluginManager'), + $container->get('VuFind\Search\Options\PluginManager') + ); } }