Search code examples
moodlemoodle-apimoodle-mobilemoodle-thememoodle-boost

How to validate something before installing local plugin in moodle


I have developed a local plugin and before installation i want to check if a certain plugin i.e. mod_attendance exists in the moodle, if it exists i want to continue with the normal installation else if the mod_attendance doesn't exist i want to return a error message and exit installation. My local plugin works on top of the mod_attendace plugin so i want to check if this plugin exists or not.

I don't know which files to add or edit in my local plugin to add validations before installation.

Your help is appreciated.


Solution

  • In your plugin's version.php, just declare that mod_attendance is a dependency for your plugin, then Moodle will take care of preventing it being installed without it.

    $plugin->dependencies = ['mod_attendance' => ANY_VERSION];
    

    See https://docs.moodle.org/dev/version.php for more details.