mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-72720 filter: Implement enable_plugin() method
This commit is contained in:
parent
0543ea7f02
commit
e76c7375e2
@ -72,10 +72,8 @@ switch ($action) {
|
||||
|
||||
case 'setstate':
|
||||
if (isset($filters[$filterpath]) and $newstate = optional_param('newstate', '', PARAM_INT)) {
|
||||
filter_set_global_state($filterpath, $newstate);
|
||||
if ($newstate == TEXTFILTER_DISABLED) {
|
||||
filter_set_applies_to_strings($filterpath, false);
|
||||
}
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('filter');
|
||||
$class::enable_plugin($filterpath, $newstate);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -83,12 +81,16 @@ switch ($action) {
|
||||
if (isset($filters[$filterpath])) {
|
||||
$applytostrings = optional_param('stringstoo', false, PARAM_BOOL);
|
||||
filter_set_applies_to_strings($filterpath, $applytostrings);
|
||||
reset_text_filters_cache();
|
||||
core_plugin_manager::reset_caches();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'down':
|
||||
if (isset($filters[$filterpath])) {
|
||||
filter_set_global_state($filterpath, $filters[$filterpath]->active, 1);
|
||||
reset_text_filters_cache();
|
||||
core_plugin_manager::reset_caches();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -96,14 +98,14 @@ switch ($action) {
|
||||
if (isset($filters[$filterpath])) {
|
||||
$oldpos = $filters[$filterpath]->sortorder;
|
||||
filter_set_global_state($filterpath, $filters[$filterpath]->active, -1);
|
||||
reset_text_filters_cache();
|
||||
core_plugin_manager::reset_caches();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Reset caches and return.
|
||||
// Return.
|
||||
if ($action) {
|
||||
reset_text_filters_cache();
|
||||
core_plugin_manager::reset_caches();
|
||||
redirect(new moodle_url('/admin/filters.php'));
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,32 @@ class filter extends base {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable a plugin.
|
||||
* When possible, the change will be stored into the config_log table, to let admins check when/who has modified it.
|
||||
*
|
||||
* @param string $pluginname The plugin name to enable/disable.
|
||||
* @param int $enabled Whether the pluginname should be TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_DISABLED.
|
||||
*
|
||||
* @return bool It always return true because we don't know if the value has changed or not. That way, we guarantee any action
|
||||
* required if it's changed will be executed.
|
||||
*/
|
||||
public static function enable_plugin(string $pluginname, int $enabled): bool {
|
||||
global $CFG;
|
||||
require_once("$CFG->libdir/filterlib.php");
|
||||
require_once("$CFG->libdir/weblib.php");
|
||||
|
||||
filter_set_global_state($pluginname, $enabled);
|
||||
if ($enabled == TEXTFILTER_DISABLED) {
|
||||
filter_set_applies_to_strings($filterpath, false);
|
||||
}
|
||||
|
||||
reset_text_filters_cache();
|
||||
\core_plugin_manager::reset_caches();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_settings_section_name() {
|
||||
return 'filtersetting' . $this->name;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user