Koha::FrameworkPlugin - Facilitate use of plugins in MARC/items editor
use Koha::FrameworkPlugin; my $plugin = Koha::FrameworkPlugin({ name => 'EXAMPLE.pl' }); $plugin->build( { id => $id }); $template->param( javascript => $plugin->javascript, noclick => $plugin->noclick, ); use Koha::FrameworkPlugin; my $plugin = Koha::FrameworkPlugin({ name => 'EXAMPLE.pl' }); $plugin->launch( { cgi => $query });
A framework plugin provides additional functionality to a MARC or item field. It can be attached to a field in the framework structure. The functionality is twofold: - Additional actions on the field via javascript in the editor itself via events as onfocus, onblur, etc. Focus may e.g. fill an empty field, Blur or Change may validate. - Provide an additional form to edit the field value, possibly a combination of various subvalues. Look at e.g. MARC leader. The additional form is a popup on top of the MARC/items editor. The plugin code is a perl script (with template for the popup), essentially doing two things: 1) Build: The plugin returns javascript to the caller (addbiblio.pl a.o.) 2) Launch: The plugin launches the additional form (popup). Launching is centralized via the plugin_launcher.pl script. This object support two code styles: - In the new style, the plugin returns a hashref with a builder and a launcher key pointing to two anynomous subroutines. - In the old style, the builder is subroutine plugin_javascript and the launcher is subroutine plugin. For each plugin the routines are redefined. In cataloguing/value_builder/EXAMPLE.pl, you can find a detailed example of a new style plugin. As long as we support the old style plugins, the unit test t/db_dependent/FrameworkPlugin.t still contains an example of the old style too.
Create object (via Class::Accessor).
Build uses the builder subroutine of the plugin to build javascript for the plugin.
Run the popup of the plugin, as defined by the launcher subroutine.
Filename of the plugin.
Optional pathname of the plugin. By default plugins are found in cataloguing/value_builder.
Error message. If set, the plugin will no longer build or launch.
Generated javascript for the caller of the plugin (after building).
Tells you (after building) that this plugin has no action connected to to clicking on the buttonDot anchor. (Note that some item plugins redirect click to focus instead of launching a popup.)
Returns new object based on Class::Accessor, loads additional params. The params hash currently supports keys: name, path, item_style. Name is mandatory. Path is used in unit testing. Item_style is used to identify old-style item plugins that still use an additional (irrelevant) first parameter in the javascript event functions.
Generate html and javascript by calling the builder sub of the plugin. Params is a hashref supporting keys: id (=html id for the input field), record (MARC record or undef), dbh (database handle), tagslib, tabloop. Note that some of these parameters are not used in most (if not all) plugins and may be obsoleted in the future (kept for now to provide backward compatibility). The most important one is id; it is used to construct unique javascript function names. Returns success or failure.
Launches the popup for this plugin by calling its launcher sub Old style plugins still expect to receive a CGI oject, new style plugins expect a params hashref. Returns undef on failure, otherwise launcher return value (if any).
Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands