"$plugin" or "$module"?

"$plugin" or "$module"?

by Joseph Rézeau -
Number of replies: 9
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

When recently updating one of my activity modules, I got confused with the naming convention used for "plugin" and "module" in the version.php file.

The version.php doc gives a comprehensive list of all compulsory and optional variables to be contained in that file: $plugin->version, $plugin->requires, etc. It also says:

    Note! For Activity modules replace $plugin-> with $module-> in the following example!

Does using "$plugin" rather than "$module" really make any difference? When I examine the various version.php files inside moodle version 2.6 ( dev) /mod directory, only containing core modules and files, I find the following inconsistency:

"$plugin->version" : 51 occurrences (incorrect)
"$module->version" : 22 occurrences (correct)

Can someone please explain?

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: "$plugin" or "$module"?

by Tomasz Muras -
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

So it looks like $module should be used in activities and $plugin everywhere else?

It would make more sense to me to use $plugin everywhere.

 

Tomek

 

In reply to Tomasz Muras

Re: "$plugin" or "$module"?

by Darko Miletić -

I love those Why? - Because. moments in Moodle smile

In reply to Darko Miletić

Re: "$plugin" or "$module"?

by Rex Lorenzo -

Yeah, like how the "blocks" and "modules" tables are plural, but every other table is singular. Kinda trips me up sometimes when doing SQL queries by hand.

Also, some tables are "course" and "courseid". These inconsistencies are annoying, but understandable because Moodle has a long history.

In reply to Tomasz Muras

Re: "$plugin" or "$module"?

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Since 2.6 it will be possible to use $plugin in all version.php files (including modules aka activities).

In earlier versions use $module for activities and $plugin in all other add-ons.
In reply to Joseph Rézeau

Re: "$plugin" or "$module"?

by Tomasz Muras -
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

Actually, the way it is now is as follows:

All main version.php files for modules (mod/*/version.php) use $module.

Every other version.php (including plugins for activities, eg /mod/assign/feedback/*/version.php) use $plugin.

I don't know why smile

Tomek

Average of ratings: Useful (1)
In reply to Tomasz Muras

Re: "$plugin" or "$module"?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, modules were the first sort of add-on for Moodle, and did things a particular way. Not all of that made sense for other types of add on.

After modules came other sorts of add-on like blocks, which used to handle version numbers in a completely different way.

Then more recently we have had a move to make all different types of add-on work more consistently in common areas like install, upgrade capabilities, cron, events, etc. That is why now almost all types of plugin use $plugin in version.php. However, they decided not to break backwards compatibility for modules by requiring $module to be changed to $plugin there.

It might still happen. It could be done like this:

  1. Make it possible to use either $module or $plugin in mod/.../version.php.
  2. Add a developer debug warning advising you to update your code when the system detects you have used $module not $plugin.
  3. Remove support for $module.

This would need to be done over several major releases. I would vote for doing at least 1. in Moodle 2.7.

Average of ratings: Useful (3)
In reply to Tim Hunt

Re: "$plugin" or "$module"?

by Tomasz Muras -
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

Yeah, I would also go with:

1. Make it possible to use either $module or $plugin in mod/.../version.php.

plus update of documentation asap - which means 2.7...

Tomek

In reply to Tomasz Muras

Re: "$plugin" or "$module"?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thanks, Thomasz and Darko for your replies, which do not shed much light on this matter but at least "comfort me in my doubts".

Joseph mixed