Note: You are currently viewing documentation for Moodle 4.0. Up-to-date documentation for the latest stable version of Moodle may be available here: Developing plugins for Moodle Workplace.

Developing plugins for Moodle Workplace

From MoodleDocs
Revision as of 11:24, 18 May 2022 by Marina Glancy (talk | contribs) (Created page with "Third party plugins may be developed specifically for Moodle Workplace or they can be developed so they can work on both Moodle LMS and Moodle Workplace. If a plugin is devel...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Third party plugins may be developed specifically for Moodle Workplace or they can be developed so they can work on both Moodle LMS and Moodle Workplace.

If a plugin is developed to work on Moodle Workplace only, include in version.php a strict dependency to the Workplace plugin that you need to use in your plugin, for example:

   $plugin->dependencies = array(
       'tool_program' => 2022031610, 
   );

If you want to include optional code that should be executed only on Moodle Workplace, for example, first you need to check that the relevant Workplace plugin exists, here are some examples of how to do it:

   // Check that specific class exists:
   if (class_exists('tool_program\api')) {
       // ....
   }
   // Check if the specific plugin is installed:
   if (\core_component::get_component_directory('tool_program')) {
       // ....
   }
   // Check that specific plugin is installed and the version is bigger than:
   if (\core_component::get_component_directory('tool_program') && get_config('version', 'tool_plugin') >= 2022031610) {
       // ....
   }

For multi-tenancy callbacks it is convenient to use the function component_class_callback() - this function will return default value if the class or method is not found. This is the best way to filter users list based on multi-tenancy. Quick example:

   // Normal query:
   $sql = "SELECT u.* FROM {user} u WHERE u.deleted = 0";
   // Modified query:
   // Add tenant condition.
   /** @uses \tool_tenant\tenancy::get_users_subquery */
   $tenantcondition = component_class_callback('tool_tenant\\tenancy', 'get_users_subquery',
       [true, true, 'u.id'], );
   $sql = "SELECT u.* FROM {user} u WHERE $tenantcondition u.deleted = 0"

Find more examples and explanations in the admin/tool/tenant/README.md