diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 2475b5eac28989ae929ced3e07f67c3204f799c0..4fb40cacff5b953774cf49411f19cb228b3ee4e6 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -318,11 +318,26 @@ $config = array( ), 'recordtab_plugin_manager' => array( 'abstract_factories' => array('VuFind\RecordTab\PluginFactory'), + 'factories' => array( + 'holdingsils' => function ($sm) { + // If VuFind is configured to suppress the holdings tab when the + // ILS driver specifies no holdings, we need to pass in a connection + // object: + $config = \VuFind\Config\Reader::getConfig(); + if (isset($config->Site->hideHoldingsTabWhenEmpty) + && $config->Site->hideHoldingsTabWhenEmpty + ) { + $catalog = $sm->getServiceLocator()->get('VuFind\ILSConnection'); + } else { + $catalog = false; + } + return new \VuFind\RecordTab\HoldingsILS($catalog); + }, + ), 'invokables' => array( 'description' => 'VuFind\RecordTab\Description', 'excerpt' => 'VuFind\RecordTab\Excerpt', 'hierarchytree' => 'VuFind\RecordTab\HierarchyTree', - 'holdingsils' => 'VuFind\RecordTab\HoldingsILS', 'holdingsworldcat' => 'VuFind\RecordTab\HoldingsWorldCat', 'map' => 'VuFind\RecordTab\Map', 'reviews' => 'VuFind\RecordTab\Reviews', diff --git a/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php b/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php index 1b8dd3a30185513eea33fa8f9b906b0dde5f3baa..2c4d17f8c672b0ec06102b7aae5ad161df896776 100644 --- a/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php +++ b/module/VuFind/src/VuFind/RecordTab/HoldingsILS.php @@ -38,6 +38,25 @@ namespace VuFind\RecordTab; */ class HoldingsILS extends AbstractBase { + /** + * ILS connection (or false if not applicable) + * + * @param \VuFind\ILS\Connection|bool + */ + protected $catalog; + + /** + * Constructor + * + * @param \VuFind\ILS\Connection|bool $catalog ILS connection to use to check + * for holdings before displaying the tab; set to false if no check is needed + */ + public function __construct($catalog) + { + $this->catalog = ($catalog && $catalog instanceof \VuFind\ILS\Connection) + ? $catalog : false; + } + /** * Get the on-screen description for this tab. * @@ -47,4 +66,17 @@ class HoldingsILS extends AbstractBase { return 'Holdings'; } + + /** + * Is this tab active? + * + * @return bool + */ + public function isActive() + { + if ($this->catalog) { + return $this->catalog->hasHoldings($this->driver->getUniqueID()); + } + return true; + } } \ No newline at end of file