Skip to content

Commit

Permalink
MDL-74584 admin: Add callback executed prior to enabling a module
Browse files Browse the repository at this point in the history
Adds a callback xxx_pre_enable_plugin_actions in admin/modules.php
which plugins can use to force additional actions before enabling the
plugin. The return value (bool) from the plugin callback method
specifies whether the process of enabling the plugin should continue
after the added actions or not.
  • Loading branch information
Mihail Geshoski committed May 6, 2022
1 parent e36fb75 commit b4f6816
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 15 additions & 4 deletions admin/modules.php
Expand Up @@ -38,11 +38,22 @@
}

if (!empty($show) and confirm_sesskey()) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($show, true);
$canenablemodule = true;
$modulename = $show;

// Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications,
// modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin
// should continue after these actions or not.
if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) {
$canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions');
}

admin_get_root(true, false); // settings not required - only pages
redirect(new moodle_url('/admin/modules.php'));
if ($canenablemodule) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($show, true);
admin_get_root(true, false); // Settings not required - only pages.
redirect(new moodle_url('/admin/modules.php'));
}
}

echo $OUTPUT->header();
Expand Down
7 changes: 7 additions & 0 deletions admin/upgrade.txt
@@ -1,5 +1,12 @@
This files describes API changes in /admin/*.

=== 4.0.1 ===

* A new callback xxx_pre_enable_plugin_actions has been added in admin/modules.php. Plugins can use this callback to
force additional actions (e.g. displaying notifications, modals, etc.) before enabling the plugin. The expected
return value (bool) from the plugin callback method specifies whether the process of enabling the plugin should
continue after the added actions or not.

=== 3.11 ===

* New admin setting admin_setting_encryptedpassword allows passwords in admin settings to be
Expand Down

0 comments on commit b4f6816

Please sign in to comment.