Plugins traffic

A local plugin that contains common classes and functions for other plugins to use?

 
Picture of Mike Finch
A local plugin that contains common classes and functions for other plugins to use?
 

I have several general purpose classes in my local plugins,  Also several general purpose functions in each plugin's locallib.php.  I have been copying them verbatim from one plugin to another, and only changing the local_[pluginname] prefix. 

I have three such local plugins as part of my Moodle website now, with duplicates of those general purpose classes and functions.  It would be nice if they were in just one place.  Would it be a terrible transgression of Moodle fashion to move those general purpose classes and functions to one common local plugin, and have the other plugins depend on and include files from that common plugin?  Does anybody do it that way?

I know that common classes and functions are usually defined in a moodle/lib/somethinglib.php file, or in a moodle/lib/classes/something.php file.  But, I am trying to steer clear of adding any files in the core Moodle, and keep all my stuff in local plugins.

 
Average of ratings: -
Picture of Justin Hunt
Re: A local plugin that contains common classes and functions for other plugins to use?
Particularly helpful MoodlersPlugin developers

You can do just as you said, put all your common classes in one plugin and reference them from another. This is made a bit safer by declaring plugin dependency in the the client plugin's version.php.

See plugin dependencies on this page https://docs.moodle.org/dev/version.php

This is how the classic Poodll plugins work. They all rely on the functionality in the Poodll filter. Well there are pros and cons to this approach. There is something to be said for the simplicity of keeping it all in one plugin, even if it makes the developers job harder.

 
Average of ratings: Useful (1)
Picture of Mike Churchward
Re: A local plugin that contains common classes and functions for other plugins to use?
Core developersParticularly helpful MoodlersPlugin developersPlugins guardiansTesters

Also, you can bundle the plugins that depend on each other as a set in the plugins database. See https://moodle.org/plugins/browse.php?list=set&id=72 for an example.

 
Average of ratings: -