Utilizing Laminas in VuFind®
VuFind® Leipzig 2024: Future Discoveries · 01.10.2024 · Leipzig
A small starter: Manipulating the template stack
Use case
You have a composer package that uses a partial view. You don't want to define and integrate a corresponding VuFind® theme with just that partial.
- modify the
template_path_stackproperty of the Laminas view manager - use a static method to obtain the path to the partial directory
A small starter: Manipulating the template stack
$config = [
'view_manager' => [
'template_path_stack' => [
'subhh-vufind-family' => SUBHH\VuFind\Family\ResourceLocator::getResourceDirectory(),
SUBHH\VuFind\RecordDescription\ResourceLocator::getResourceDirectory(),
],
],
];Events
Laminas uses an event bus to manage the lifecycle of an application. You can hook into the system to modify the behavior of the application.
public function attach (SharedEventManagerInterface $events) : void
{
$events->attach('*', MvcEvent::EVENT_DISPATCH_ERROR, [$this, 'onError']);
$events->attach('*', MvcEvent::EVENT_RENDER_ERROR, [$this, 'onError']);
}Events
Use case 1
You want to provide more differentiated HTTP status codes and error pages in case something goes wrong. I.e. if the index is down, send a 502 error code with a informative page for the user.
- hook into the
dispatch.errorandrender.errorevents - check the error condition and set the status code
- replace the view model if necessary
Events
Use case 2
You facet over a field with location codes. Due to reorganization, the location codes change such that multiple codes refer to the same location. You can't change the index.
- hook into the
search.postevent and merge the respective facet values - hook into the
search.preevent and modify thefqparameter
Events
Use case 3
You want to collect performance data of your search index usage.
- hook into the
search.pre,search.post, andsearch.errorevents - track each search command passing through
Maus, David. “Analyzing, Understanding and (hopefully) Fixing Degraded Search Performance”. Presented at the WOLFcon 2023, Chicago, IL, August 24, 2023.
DOI 10.5281/zenodo.8279989.