Customizing RecordManager - NatLibFi/RecordManager GitHub Wiki
Customizing RecordManager
RecordManager uses Laminas module manager and service manager to instantiate services. It also uses plugin managers for several classes of services.
Active modules are specified in conf/modules.config.php
. You can copy the provided conf/modules.config.php.sample
to conf/modules.config.php
and modify it accordingly. The examples below leave out any comments for clarity, but it is recommended to verify that vendor/bin/phing ci-tasks
completes successfully with any custom modules active, and that would require e.g. phpdoc comments to be in place.
A minimal module ("Sample" in this example) consists of the following file:
src/RecordManager/Sample/Module.php
The file needs to contain a Module class that provides the module configuration:
<?php
namespace RecordManager\Sample;
class Module
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
module.config.php provides information on what classes the module adds or overrides (see aliases below) and how to instantiate them:
return [
'recordmanager' => [
'plugin_managers' => [
'record' => [
'factories' => [
\RecordManager\Sample\Record\Marc::class => \RecordManager\Base\Record\AbstractRecordFactory::class,
],
'aliases' => [
\RecordManager\Base\Record\Marc::class => \RecordManager\Sample\Record\Marc::class,
],
]
]
]
];
Above configuration defines that when RecordManager tries to create a Marc class, it will use the \RecordManager\Sample\Record\Marc
class.
Now all that's left to do it add the class to file src/RecordManager/Sample/Record/Marc.php:
namespace RecordManager\Sample\Record;
class Marc extends \RecordManager\Base\Record\Marc
{
public function toSolrArray(Database $db = null)
{
$data = parent::toSolrArray($db);
$data['custom_field_txt_mv'] = ['custom', 'values'];
}
}
N.B. Make sure the namespace declarations are correct and match the module name. Also make sure the class names match the file names. These allow the autoloader to find the class implementation.