From fbb4b97b420b5c9e8963af20aae7d4f09618fe58 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 22 Feb 2018 08:51:37 -0500
Subject: [PATCH] Allow custom hidden filters for collections.

---
 config/vufind/Collection.ini                     |  7 +++++++
 .../src/VuFind/Search/SolrCollection/Params.php  | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/config/vufind/Collection.ini b/config/vufind/Collection.ini
index d9657c35444..75f37a8d178 100644
--- a/config/vufind/Collection.ini
+++ b/config/vufind/Collection.ini
@@ -63,3 +63,10 @@ title = sort_title
 year = sort_year
 year asc = "sort_year asc"
 author = sort_author
+
+; See searches.ini for documentation on these sections. Collections will always
+; use the filters applied in searches.ini; any additional filters defined here
+; will be combined with those existing filters. Use these if you want to apply
+; additional filtering to records displayed in the collection context.
+;[HiddenFilters]
+;[RawHiddenFilters]
\ No newline at end of file
diff --git a/module/VuFind/src/VuFind/Search/SolrCollection/Params.php b/module/VuFind/src/VuFind/Search/SolrCollection/Params.php
index fc5a8c112b8..ed9adb96054 100644
--- a/module/VuFind/src/VuFind/Search/SolrCollection/Params.php
+++ b/module/VuFind/src/VuFind/Search/SolrCollection/Params.php
@@ -90,6 +90,22 @@ class Params extends \VuFind\Search\Solr\Params
         $safeId = addcslashes($this->collectionID, '"');
         $this->addHiddenFilter($this->collectionField . ':"' . $safeId . '"');
         $this->addHiddenFilter('!id:"' . $safeId . '"');
+
+        // Because the [HiddenFilters] and [RawHiddenFilters] settings for the
+        // Solr search backend come from searches.ini and are set up in the
+        // AbstractSolrBackendFactory, we need to account for additional ones
+        // from Collection.ini here.
+        $collectionConfig = $this->configLoader->get('Collection');
+        if (isset($collectionConfig->HiddenFilters)) {
+            foreach ($collectionConfig->HiddenFilters as $field => $value) {
+                $this->addHiddenFilter(sprintf('%s:"%s"', $field, $value));
+            }
+        }
+        if (isset($collectionConfig->RawHiddenFilters)) {
+            foreach ($collectionConfig->RawHiddenFilters as $current) {
+                $this->addHiddenFilter($current);
+            }
+        }
     }
 
     /**
-- 
GitLab