How to create new plugin type in Moodle/Totara?

| By Webner

Introduction plugin types in Moodle/Totara

As we know, Moodle/Totara has multiple plugin types. To extend core functionality, different ways are used to create each plugin type.

Some of the plugin types are:

  • mod
  • blocks
  • theme
  • availability
  • report
  • auth
  • local etc.

If you want to create a new plugin type, then you have to make a change in the core file

For example:
In this example, we will create a plugin type named “courseavailabiliy”. To create it, we have to make two changes in the above-listed file.

  1. Firstly, we create the “courseavailability” folder in the root folder of your Totara.
  2. Now, add below line at the end of “fetch_subsystems()” function:

    ‘courseavailability’ => $CFG->dirroot . ‘/courseavailability’;

  3. “fetch_subsystems()” returns a list of core subsystems. Subsystems in Moodle don’t seem to be plugins themselves. These are groups of related functions and classes that are part of the core but are logically grouped together. They can be referred to using core_xxx where xxx is the subsystem name.

  4. After that, please paste the below line at the end of the “fetch_plugintypes()” function:

    ‘courseavailability’ => $CFG->dirroot . ‘/courseavailability/’;

    By calling this function, you can get a list of available plugin types together with their location.

  5. If you want to use your own language strings, then you need to create a plugin type file under this “lang/en/”. You need to name this file the same plugin type name. In our example, we have created a “courseavailability” so my language file name is “courseavailability.php”.
  6. Now, you have to create a plugin info class for this plugin type. As we know, a plugin info class describes the properties of your plugins like plugin settings, plugin status, and plugin actions(install, uninstall).

    You have to place this file in “/lib/classes/pluginginfo”. This filename will be the same as the plugin type name. In our example, we create “courseavailability.php”.

Note: If you want to create the new plugin of this new one, then you have to place your plugin into the ‘/courseavailability/’ directory.

Leave a Reply

Your email address will not be published. Required fields are marked *