mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-72720 format: Implement enable_plugin() method
This commit is contained in:
parent
e76c7375e2
commit
105be1edc1
@ -47,17 +47,14 @@ if (!isset($formatplugins[$formatname])) {
|
||||
switch ($action) {
|
||||
case 'disable':
|
||||
if ($formatplugins[$formatname]->is_enabled()) {
|
||||
if (get_config('moodlecourse', 'format') === $formatname) {
|
||||
print_error('cannotdisableformat', 'error', $return);
|
||||
}
|
||||
set_config('disabled', 1, 'format_'. $formatname);
|
||||
core_plugin_manager::reset_caches();
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('format');
|
||||
$class::enable_plugin($formatname, false);
|
||||
}
|
||||
break;
|
||||
case 'enable':
|
||||
if (!$formatplugins[$formatname]->is_enabled()) {
|
||||
unset_config('disabled', 'format_'. $formatname);
|
||||
core_plugin_manager::reset_caches();
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('format');
|
||||
$class::enable_plugin($formatname, true);
|
||||
}
|
||||
break;
|
||||
case 'up':
|
||||
|
@ -65,6 +65,33 @@ class format extends base {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
public static function enable_plugin(string $pluginname, int $enabled): bool {
|
||||
$haschanged = false;
|
||||
|
||||
$plugin = 'format_' . $pluginname;
|
||||
$oldvalue = get_config($plugin, 'disabled');
|
||||
$disabled = !$enabled;
|
||||
// Only set value if there is no config setting or if the value is different from the previous one.
|
||||
if ($oldvalue == false && $disabled) {
|
||||
if (get_config('moodlecourse', 'format') === $pluginname) {
|
||||
// The default course format can't be disabled.
|
||||
throw new \moodle_exception('cannotdisableformat', 'error');
|
||||
}
|
||||
set_config('disabled', $disabled, $plugin);
|
||||
$haschanged = true;
|
||||
} else if ($oldvalue != false && !$disabled) {
|
||||
unset_config('disabled', $plugin);
|
||||
$haschanged = true;
|
||||
}
|
||||
|
||||
if ($haschanged) {
|
||||
add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
|
||||
\core_plugin_manager::reset_caches();
|
||||
}
|
||||
|
||||
return $haschanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gathers and returns the information about all plugins of the given type
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user