Skip to content

Commit

Permalink
Display search errors correctly in combined search mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Dec 4, 2024
1 parent 7da2951 commit 5ab565f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion module/VuFind/src/VuFind/Controller/AbstractSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ protected function getSearchResultsView($setupCallback = null)
$view = $this->createViewModel();
$config = $this->getConfig($this->getOptionsForClass()->getFacetsIni());
$view->multiFacetsSelection = (bool)($config->Results_Settings->multiFacetsSelection ?? false);
$extraErrors = [];

// Handle saved search requests:
$savedId = $this->params()->fromQuery('saved', false);
Expand Down Expand Up @@ -427,7 +428,14 @@ protected function getSearchResultsView($setupCallback = null)
}

foreach ($results->getErrors() as $error) {
$this->flashMessenger()->addErrorMessage($error);
try {
$this->flashMessenger()->addErrorMessage($error);
} catch (\Exception $e) {
// The flash messenger will throw an exception if session writes are disabled,
// which will happen in combined search AJAX requests. For that situation, we'll
// pass error messages through the view model so they can still be displayed.
$extraErrors[] = $error;
}
}
}

Expand All @@ -439,6 +447,11 @@ protected function getSearchResultsView($setupCallback = null)
// Schedule options for footer tools
$view->scheduleOptions = $this->getService(\VuFind\Search\History::class)->getScheduleOptions();
$view->saveToHistory = $this->saveToHistory;

// Add extra errors, if necessary:
if (count($extraErrors) > 0) {
$view->extraErrors = $extraErrors;
}
return $view;
}

Expand Down
3 changes: 3 additions & 0 deletions module/VuFind/src/VuFind/Controller/CombinedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public function resultAction()
'currentSearch' => $settings,
'domId' => 'combined_' . str_replace(':', '____', $sectionId),
];
if (!empty($settings['view']->extraErrors)) {
$viewParams['extraErrors'] = $settings['view']->extraErrors;
}
// Initialize theme resources:
($this->getViewRenderer()->plugin('setupThemeResources'))(true);
// Render content:
Expand Down
4 changes: 4 additions & 0 deletions themes/bootstrap3/templates/combined/results-list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
</div>
<?php /* End Listing Options */ ?>

<?php foreach($this->extraErrors ?? [] as $error): ?>
<div class="alert alert-danger"><?=$this->transEsc($error)?></div>
<?php endforeach; ?>

<?php if ($recordTotal < 1): ?>
<p class="alert alert-danger">
<?=$this->slot('empty-message')->get($this->translate('nohit_lookfor_html', ['%%lookfor%%' => $this->escapeHtml($lookfor)])); ?>
Expand Down
4 changes: 4 additions & 0 deletions themes/bootstrap5/templates/combined/results-list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
</div>
<?php /* End Listing Options */ ?>

<?php foreach($this->extraErrors ?? [] as $error): ?>
<div class="alert alert-danger"><?=$this->transEsc($error)?></div>
<?php endforeach; ?>

<?php if ($recordTotal < 1): ?>
<p class="alert alert-danger">
<?=$this->slot('empty-message')->get($this->translate('nohit_lookfor_html', ['%%lookfor%%' => $this->escapeHtml($lookfor)])); ?>
Expand Down

0 comments on commit 5ab565f

Please sign in to comment.