About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:code_generators

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
development:code_generators [2017/08/02 17:58] demiankatzdevelopment:code_generators [2018/02/07 20:53] demiankatz
Line 59: Line 59:
 </code> </code>
  
-===== Overriding Existing Plugins and Services =====+===== Overriding Existing Plugins and Services (VuFind 4.x and earlier) =====
  
 If you want to extend one of VuFind's built-in plugins or services, you can use the 'extendservice' generator to create a new subclass and automatically configure your local module to use it. If you want to extend one of VuFind's built-in plugins or services, you can use the 'extendservice' generator to create a new subclass and automatically configure your local module to use it.
 +
 +:!: Starting with VuFind 5.0, the 'extendclass' generator is usually a more convenient option. See below for details. You can still use 'extendservice' in 5.0 if you wish, but due to changes in service manager configuration, it is less useful than before.
  
 ==== Usage ==== ==== Usage ====
Line 111: Line 113:
 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 Created backup: /.../module/MyModule/config/module.config.php.1423850855.bak
 +Successfully updated /.../module/MyModule/config/module.config.php
 +</code>
 +
 +===== Overriding Existing Plugins and Services (VuFind 5.0 and later) =====
 +
 +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.
 +
 +==== Usage ====
 +
 +<code bash>
 +cd $VUFIND_HOME
 +php public/index.php generate extendclass [--extendfactory] Fully\\Qualified\\ClassName MyModule
 +</code>
 +
 +  * --extendfactory is a switch which will cause the existing factory method to be cloned into your local module. If you omit the switch, the existing factory will be used. :!: Using the existing factory only makes sense for factories that dynamically determine the name of the constructed object using the service name; however, a significant number of VuFind services use this type of factory starting in release 5.0.
 +  * Fully\\Qualified\\ClassName is the name of the class you wish to extend/override -- note the need to escape backslashes on the command line.
 +  * MyModule is the name of your local module where you wish to create a new class.
 +
 +==== Notes ====
 +:!: 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.
 +
 +==== Example ====
 +
 +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:
 +
 +<code bash>
 +cd $VUFIND_HOME
 +php public/index.php generate extendclass --extendfactory VuFind\\RecordDriver\\SolrMarc MyModule
 +</code>
 +
 +The output should look something like this:
 +
 +<code>
 +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 Successfully updated /.../module/MyModule/config/module.config.php
 </code> </code>
development/code_generators.txt · Last modified: 2023/11/09 21:19 by demiankatz