Command line code generation tools are available to help save you time when performing certain common tasks.
Adding new entries to the router configuration can involve tedious array creation, so VuFind® includes tools for creating certain kinds of routes automatically from the command line.
The most basic type of route simply specifies a controller and an action, mapping a URL path like “/Controller/Action” to the corresponding code.
cd $VUFIND_HOME php public/index.php generate staticroute Controller/Action MyModule
Simple dynamic routes are similar to static routes but allow the addition of dynamic parameters after the action name. This is useful for actions that need to, for example, retrieve specific values by ID (like the existing routes that load user favorite lists).
cd $VUFIND_HOME php public/index.php generate dynamicroute routename Controller Action/[:placeholders] MyModule
Record routes are a special complex case which handle the creation of multiple route entries for a record home page, dynamic tab URLs, and a set of standard static routes. These do not commonly need to be generated, but they may be needed when creating a new search backend.
cd $VUFIND_HOME php public/index.php generate recordroute routename-base Controller MyModule
Starting with VuFind® 4.1, a generator is available to create an example theme for you to customize. The generator not only creates a new theme directory with an example configuration, CSS and template, but it also updates your local config.ini to turn on the new theme and make it a selectable option.
cd $VUFIND_HOME php public/index.php generate theme MyTheme
Starting with VuFind® 4.1, a generator is available to create an example theme mix-in for you to customize. The generator creates a new mix-in directory with an example configuration and script; you will need to manually customize this and add it to your theme.config.php's mixins array in order to activate it.
cd $VUFIND_HOME php public/index.php generate thememixin MyMixin
If you want to extend one of VuFind®'s built-in plugins or services, you can use the 'extendclass' generator to create a new subclass and automatically configure your local module to use it.
cd $VUFIND_HOME php public/index.php generate extendclass [--extendfactory] Fully\\Qualified\\ClassName MyModule
Be sure that MyModule already exists and is included in your VUFIND_LOCAL_MODULES environment variable, or the generator may not work correctly. If MyModule does not yet exist, you can re-run VuFind®'s install.php script to create it.
If things don't work right away after generating code, you may need to clear your local/cache directory to get rid of outdated configurations.
Suppose you wish to create a custom subclass of VuFind®'s SolrMarc record driver. The command to generate a custom extension of the default class is:
cd $VUFIND_HOME php public/index.php generate extendclass --extendfactory VuFind\\RecordDriver\\SolrMarc MyModule
The output should look something like this:
Saved file: /.../module/MyModule/src/MyModule/RecordDriver/SolrMarc.php Saved file: /.../module/MyModule/src/MyModule/RecordDriver/Factory.php Saved file: /.../module/MyModule/src/MyModule/RecordDriver/Factory.php Created backup: /.../module/MyModule/config/module.config.php.1423850855.bak Successfully updated /.../module/MyModule/config/module.config.php Successfully updated /.../module/MyModule/config/module.config.php
You can also use the 'extendservice' generator to create a new subclass and automatically configure your local module to use it. It is recommended that you use 'extendclass' instead, because 'extendservice' is a legacy tool that became less useful when 'extendclass' was introduced in release 5.0. However, 'extendservice' remains available as an alternative approach.
cd $VUFIND_HOME php public/index.php generate extendservice path/to/service MyModule
Be sure that MyModule already exists and is included in your VUFIND_LOCAL_MODULES environment variable, or the generator may not work correctly. If MyModule does not yet exist, you can re-run VuFind®'s install.php script to create it.
If things don't work right away after generating code, you may need to clear your local/cache directory to get rid of outdated configurations.
Don't forget to escape backslashes in service names within the path/to/service parameter. For example, if you wanted to override the export tool, your path would be “service_manager/factories/VuFind\\Export”.
Suppose you wish to create a custom subclass of VuFind®'s SolrMarc record driver. You can see in module/VuFind/config/module.config.php that the plugin is defined like this:
$config = array( 'vufind' => array( ... 'plugin_managers' => array( ... 'recorddriver' => array( ... 'factories' => array( ... 'solrmarc' => 'VuFind\RecordDriver\Factory::getSolrMarc',
The path to this service would be vufind/plugin_managers/recorddriver/factories/solrmarc (following the nested arrays down from the top). So the command to generate a custom extension of the default class is:
cd $VUFIND_HOME php public/index.php generate extendservice vufind/plugin_managers/recorddriver/factories/solrmarc MyModule
The output should look something like this:
Saved file: /.../module/MyModule/src/MyModule/RecordDriver/Factory.php Saved file: /.../module/MyModule/src/MyModule/RecordDriver/SolrMarc.php Saved file: /.../module/MyModule/src/MyModule/RecordDriver/Factory.php Created backup: /.../module/MyModule/config/module.config.php.1423850855.bak Successfully updated /.../module/MyModule/config/module.config.php
This feature was introduced in VuFind® 5.1.
If you want to create a new plugin for VuFind®, you can use the 'plugin' generator to create a stub class and (if necessary) factory and automatically update the relevant module configuration.
cd $VUFIND_HOME php public/index.php generate plugin MyModule\\PluginType\\PluginName [optional factory name]
Be sure that MyModule already exists and is included in your VUFIND_LOCAL_MODULES environment variable, or the generator may not work correctly. If MyModule does not yet exist, you can re-run VuFind®'s install.php script to create it.
If things don't work right away after generating code, you may need to clear your local/cache directory to get rid of outdated configurations.
Suppose you want to create a new ILS driver for your home-grown system. You could begin like this:
cd $VUFIND_HOME php public/index.php generate plugin MyModule\\ILS\\Driver\\MyLocalSystem
The output should look something like this:
Saved file: /home/dkatz/vufind3/module/MyModule/src/MyModule/ILS/Driver/MyLocalSystem.php Saved file: /home/dkatz/vufind3/module/MyModule/src/MyModule/ILS/Driver/MyLocalSystemFactory.php Created backup: /home/dkatz/vufind3/module/MyModule/config/module.config.php.1540394754.bak Successfully updated /home/dkatz/vufind3/module/MyModule/config/module.config.php Successfully updated /home/dkatz/vufind3/module/MyModule/config/module.config.php
See the Code Generators Part 1 and Code Generators Part 2 videos for some examples of code generators in action.