====== Displaying a Custom Field: VuFind® 6.x (or newer) Example ======
// This example shows you how to set up a custom module, custom theme and custom record driver. It assumes that you have already added a custom field to your Solr index named RecID -- you can see more concrete examples of adding fields on the [[indexing:adding_facets|Adding Facets]] page. //
1. Create a custom module (if you haven't already done so)
cd $VUFIND_HOME
php install.php
* At the prompt "What module name would you like to use? [blank for none]" type in your module name
* Link configuration to apache’s config.d directory per the install.php directions
* Restart apache (sudo systemctl restart apache2, or whatever equivalent command is appropriate in your environment)
2. Make sure that your module name is exported in an environment variable so that generator commands work correctly:
export VUFIND_LOCAL_MODULES=ModuleName
3. From $VUFIND_HOME enter the following code generator command:
php public/index.php generate extendclass VuFind\\RecordDriver\\SolrMarc ModuleName
* You should see something similar to the following:
Saved file: /home/dkatz/vufind3/module/ModuleName/src/ModuleName/RecordDriver/SolrMarc.php
Created backup: /home/dkatz/vufind3/module/ModuleName/config/module.config.php.1586866995.bak
Successfully updated /home/dkatz/vufind3/module/ModuleName/config/module.config.php
Successfully updated /home/dkatz/vufind3/module/ModuleName/config/module.config.php
Successfully updated /home/dkatz/vufind3/module/ModuleName/config/module.config.php
4. Update the $VUFIND_HOME/module/ModuleName/src/ModuleName/RecordDriver/SolrMarc.php file to add a new field.
* Make sure the namespace line reads “namespace ModuleName\RecordDriver;”
* Add the getter method. See below for an example, but also reference the SolrMarc.php, MarcBasicTrait.php and MarcAdvancedTrait.php files in /module/VuFind/src/VuFind/RecordDriver/ for more examples of getter code.
Example:
fields['recID'] ?? '';
}
}
5. To add the new field to a result list, you will need to set up a custom theme (if you don't already have one) and copy the appropriate files into it.
* First, set up the necessary directory structure:
cd $VUFIND_HOME/themes
mkdir -p ThemeName/templates/RecordDriver/SolrMarc/
* Put the following content in $VUFIND_HOME/themes/ThemeName/theme.config.php:
'bootstrap3'
];
* Copy $VUFIND_HOME/themes/bootstrap3/templates/RecordDriver/DefaultRecord/result-list.phtml into your new theme’s SolrMarc directory (e.g. cp $VUFIND_HOME/themes/bootstrap3/templates/RecordDriver/DefaultRecord/result-list.phtml $VUFIND_HOME/themes/ThemeName/templates/RecordDriver/SolrMarc/). Note that copying the file into the SolrMarc directory will ONLY override the template for MARC records. If you wanted to override it for every type of record, you would instead copy it into the custom theme's DefaultRecord directory.
* Edit $VUFIND_HOME/themes/ThemeName/templates/RecordDriver/SolrMarc/result-list.phtml to add the new field for display.
For example, you could add this immediately preceding the div with a class of "callnumAndLocation":
$recordID = $this->driver->getRecordID(); if (!empty($recordID)): ?>