MDL-72720 editor: Implement enable_plugin() method
This commit is contained in:
@@ -51,6 +51,42 @@ class editor extends base {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
public static function enable_plugin(string $pluginname, int $enabled): bool {
|
||||
global $CFG;
|
||||
|
||||
$haschanged = false;
|
||||
if (!empty($CFG->texteditors)) {
|
||||
$plugins = array_flip(explode(',', $CFG->texteditors));
|
||||
} else {
|
||||
$plugins = [];
|
||||
}
|
||||
|
||||
// Only set visibility if it's different from the current value.
|
||||
if ($enabled && !array_key_exists($pluginname, $plugins)) {
|
||||
$plugins[$pluginname] = $pluginname;
|
||||
$haschanged = true;
|
||||
} else if (!$enabled && array_key_exists($pluginname, $plugins)) {
|
||||
unset($plugins[$pluginname]);
|
||||
$haschanged = true;
|
||||
}
|
||||
|
||||
// At least one editor must be active.
|
||||
if (empty($plugins)) {
|
||||
$plugins['textarea'] = 'textarea';
|
||||
$haschanged = true;
|
||||
}
|
||||
|
||||
if ($haschanged) {
|
||||
$new = implode(',', array_flip($plugins));
|
||||
add_to_config_log('editor_visibility', !$enabled, $enabled, $pluginname);
|
||||
set_config('texteditors', $new);
|
||||
// Reset caches.
|
||||
\core_plugin_manager::reset_caches();
|
||||
}
|
||||
|
||||
return $haschanged;
|
||||
}
|
||||
|
||||
public function get_settings_section_name() {
|
||||
return 'editorsettings' . $this->name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user