Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Subplugins

From MoodleDocs
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Sub plugins allow activity modules to be extended without having to change the module's code.

Each activity module can define a set of subplugin 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.

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';


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.