From b4f68169529f45d8275e61c8a00bfad3942870e4 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 4 May 2022 10:26:13 +0800 Subject: [PATCH] MDL-74584 admin: Add callback executed prior to enabling a module 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. --- admin/modules.php | 19 +++++++++++++++---- admin/upgrade.txt | 7 +++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/admin/modules.php b/admin/modules.php index 1ec117e82e5..3a17cf5b780 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -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; - admin_get_root(true, false); // settings not required - only pages - redirect(new moodle_url('/admin/modules.php')); + // 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'); + } + + 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(); diff --git a/admin/upgrade.txt b/admin/upgrade.txt index 6beeb3a0f42..df789ff29b9 100644 --- a/admin/upgrade.txt +++ b/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