From 3dec9d1ae708c9f07e01e21918f301ef9b022d0f Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 15 Nov 2019 11:58:42 -0500
Subject: [PATCH] Fix bugs related to default filters. - Wrong associativity of
 ternary in filters.phtml - Missing default restoration in edit history action

---
 module/VuFind/src/VuFind/Controller/SearchController.php | 4 ++++
 themes/bootstrap3/templates/search/filters.phtml         | 7 ++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php
index d49f06ea051..aa76b8607b0 100644
--- a/module/VuFind/src/VuFind/Controller/SearchController.php
+++ b/module/VuFind/src/VuFind/Controller/SearchController.php
@@ -78,7 +78,11 @@ class SearchController extends AbstractSolrSearch
         $initialParams = $factory->fromParams($params);
 
         if ($removeAllFilters) {
+            $defaultFilters = $params->getOptions()->getDefaultFilters();
             $query = $initialParams->removeAllFilters();
+            foreach ($defaultFilters as $filter) {
+                $query = $query->addFilter($filter);
+            }
         } elseif ($removeFacet) {
             $defaults = ['operator' => 'AND', 'field' => '', 'value' => ''];
             extract($removeFacet + $defaults);
diff --git a/themes/bootstrap3/templates/search/filters.phtml b/themes/bootstrap3/templates/search/filters.phtml
index d618c451bc3..dad60168423 100644
--- a/themes/bootstrap3/templates/search/filters.phtml
+++ b/themes/bootstrap3/templates/search/filters.phtml
@@ -112,11 +112,12 @@
 
 <?php if ($hasDefaultsApplied || $filterCount > 0): ?>
   <?php
-    $resetLink = $onlyDefaultsApplied
-      ? null
-      : isset($urlQuery)
+    $resetLink = null;
+    if (!$onlyDefaultsApplied) {
+      $resetLink = isset($urlQuery)
         ? $urlQuery->removeAllFilters()->resetDefaultFilters()
         : $this->searchMemory()->getEditLink($this->searchClassId, 'removeAllFilters', 1);
+    }
   ?>
   <?php // Normal view ?>
   <div class="active-filters hidden-xs">
-- 
GitLab