Difference between revisions of "Subplugins"

Jump to: navigation, search
(Settings pages)
(Defining sub-plugin type)
Line 1: Line 1:
 
==Defining sub-plugin type==
 
==Defining sub-plugin type==
  
New plugins types may be define in activity modules and since 2.6 also in local plugins and admin tools - these are called sub-plugin types.
+
Sub-plugins are supported in following plugin types:
 +
* activity modules
 +
* html editors (since 2.5)
 +
* local plugins (since 2.6)
 +
* admin tools (since 2.6)
  
 
===db/subplugins.php===
 
===db/subplugins.php===

Revision as of 12:37, 22 October 2013

Defining sub-plugin type

Sub-plugins are supported in following plugin types:

  • activity modules
  • html editors (since 2.5)
  • local plugins (since 2.6)
  • admin tools (since 2.6)

db/subplugins.php

Each activity module can define a set of sub-plugin types in db/subplugins.php. The file must contain an array called $subplugins, with the plugin type as the key for the directory containing the plugins. For example, from mod/workshop/db/subplugins.php:

$subplugins = array(
    'workshopform'       => 'mod/workshop/form',
    'workshopallocation' => 'mod/workshop/allocation',
    'workshopeval'       => 'mod/workshop/eval',
);

This defines 3 plugin types, workshopform, workshopallocation, and workshopeval. The plugins themselves can be found in mod/workshop/form, mod/workshop/allocation and mod/workshop/eval, respectively. Each of these directories can contain a number of plugins, each within it's own subdirectory.

Language strings

You also need to add an entry in the module's language strings to identify the subplugin(s). Again, using an example from Workshop in mod/workshop/lang/en/workshop.php one can find:

$string['subplugintype_workshopallocation'] = 'Submissions allocation method';
$string['subplugintype_workshopallocation_plural'] = 'Submissions allocation methods';
$string['subplugintype_workshopeval'] = 'Grading evaluation method';
$string['subplugintype_workshopeval_plural'] = 'Grading evaluation methods';
$string['subplugintype_workshopform'] = 'Grading strategy';
$string['subplugintype_workshopform_plural'] = 'Grading strategies';

Naming rules and recommendation:

  • sub-plugin types must be globally unique - they must not collide with any other plugin type, core subsystem or any other subplugin-type
  • sub-plugin type names must be short because there are limits on database table name lengths

Uninstallation support

Moodle 2.6


Since Moodle 2.6 sub-plugin types may define explicit uninstallation method. It is useful if you need to cleanup up some db tables or settings when uninstalling individual sub-plugins.

Management page

Moodle includes only basic listing of installed sub-plugins and support for sub-plugin uninstallation.

Writing a sub-plugin

A lot of the basic structure of a sub-plugin is the same as any other plugin. It can have a version.php (don't forget the object is $plugin not $mod), a lang directory, and can have a db directory with install.xml and all the others files can can go in there.

As a minimum, you will need the version.php file and a language file with 'pluginname' defined.

However the details of what APIs the sub-plugin has to provide depends on the type of sub-plugin it is. For example, and quiz report has to follow the rules for quiz reports that the quiz module sets, and a workshop allocation has to follow the rules set by the workshop module. When you create a new type of sub-plugin, you should document the expected API.

Settings pages

A subplugin can include a settings.php page but it will not be included automatically. It is the responsibility of the parent module's settings.php file to include the subplugin's settings pages. See lib/editor/tinymce/ for a real example.

Distribution of sub-plugins

Basic se of sub-plugins is usually distributed with each add-on. It is also possible to submit add-on sub-plugins separately.