This is a template of Moodle local plugins. You can use it as a boiler plate for your next plugin.
Good question! I started unexpectedly developing for Moodle. Moodle, as you may have noticed, is very academic in all its aspects even code. So you may not find the specific answer to your question quickly. And that's why this project is worth sharing. This template is a result of reading all the documentation provided in Moodle Developer DOCs. Development of few production-ready plugins for large Moodle powered platforms. And finally, this is what I am using all the time to kick start any new plugin.
Clone the project to your workspace.
git clone https://github.com/mohessaid/moodle_local_plugin.git
It's recommended to clone it to a custom name (name of your plugin).
git clone https://github.com/mohessaid/moodle_local_plugin.git my_plugin_name`
The version.php
file contains important information that helps Moodle install and
load your plugin. It looks like this:
$plugin->component = 'local_moodle_local_plugin';
$plugin->version = 2017112900;
$plugin->requires = 2014051200;
$plugin->maturity = MATURITY_ALPHA;
$plugin->release = 'v0.0.1';
$plugin->component = 'local_course_editor';
The component property is the name of your plugin. The name must be in this format type + name
. Where type is the type of our plugin, And the name is what we want to call our plugin. This naming style is necessary to allow the Moodle autoloader to load our plugin correctly. If we miss something in the name or change it in any place of our plugin, Moodle won't load it or detected it for installation if it's newly added.
The type
part must be the same with the parent folder where we willing to put our plugin. For example, local
for local plugins and mod
for module plugins. Every Moodle plugin type
has a folder in the root directory where we can put our plugins. If we are writing a child plugin, we use the appropriate folder of his parent plugin.
The name
part is what we want to name the plugin. We can call it whatever we like. If it respects the naming conventions and coding styles of Moodle.
The version property is an integer. It contains four parts and can be summiried as follow:
- The year (
2017
in this case). - The month (
11
November in this case). - The day (
29
in this case). - The version
00
. this related to the day of development or release it your choice. You wil use this part on your daily development process to check the changes that require version upgrade. If you are willing to publish this plugin in the Moodle plugins directory this part will be00
which is recommended.
This is the Moodle version required by the plugin.
How mature is the plugin. It can be one of these options ( MATURITY_ALPHA, MATURITY_BETA, MATURITY_RC or MATURITY_STABLE
).
You can use whatever you want for your plugin release versioning. Moodle core plugins uses v2.7.-r1
where 2.7
is the version of Moodle and r1
is the first revision of their 2.7.x
branch.
After we update the version.php
file with our custom choices. Now we need to rename files that should contain the name and the type of our plugin like the files unders the lang
folder. Then we have to change the functions names in the bd
folder files. For example the in the install.php
file we have this:
function xmldb_moodle_local_plugin_install(){
// Installation code goes here
}
Which needs to be updated by replacing the moodle_local_plugin
part with our plugin name. local
here is part of our default name so don't get confused with the type of plugin. In these functions you don't need to specify the type. Another example is the externallib.php
file, where we can implement our external web services to use them through the web services API.
class local_moodle_local_plugin_external extends external_api{
// Functions (methods) goes here.
}
If the getting started section is not enough for you to get going with your Moodle plugin. Please feel free to check the Moodle documentation on this matter. I included documentation links in every file. You can also check their tracking system and forums to get custom help.
- Local plugins development
- Development documentations
- Plugin files
- Moodle tracker
- Moodle forums
- Moodle developers chat rooms
- IRC channel name of the channel is
moodle
or#moodle
if the application require the hash sign. You can use it freenode irc webchat if you are not familair with these chat rooms.