MDL-77248 core: Move pre_enable_plugin_actions callback to enable_plugin

Note: The original callback was incorrectly using the $PAGE output,
which cannot be relied upon in this callback. The best we can do here is
to add a notification to explain the situation.
This commit is contained in:
Andrew Nicols
2023-02-28 12:04:50 +08:00
parent 797b76becf
commit e6fe30187f
6 changed files with 102 additions and 21 deletions
+8
View File
@@ -51,6 +51,14 @@ class mod extends base {
// Only set visibility if it's different from the current value.
if ($module->visible != $enabled) {
if ($enabled && component_callback_exists("mod_{$pluginname}", 'pre_enable_plugin_actions')) {
// 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("mod_{$pluginname}", 'pre_enable_plugin_actions')) {
return false;
}
}
// Set module visibility.
$DB->set_field('modules', 'visible', $enabled, ['id' => $module->id]);
$haschanged = true;