mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-72720 editor: Implement enable_plugin() method
This commit is contained in:
parent
e62f8ed093
commit
e8c60cff1f
@ -39,22 +39,19 @@ if (!confirm_sesskey()) {
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
|
||||
$return = true;
|
||||
switch ($action) {
|
||||
case 'disable':
|
||||
// remove from enabled list
|
||||
$key = array_search($editor, $active_editors);
|
||||
unset($active_editors[$key]);
|
||||
add_to_config_log('editor_visibility', '1', '0', $editor);
|
||||
// Remove from enabled list.
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('editor');
|
||||
$class::enable_plugin($editor, false);
|
||||
break;
|
||||
|
||||
case 'enable':
|
||||
// add to enabled list
|
||||
// Add to enabled list.
|
||||
if (!in_array($editor, $active_editors)) {
|
||||
$active_editors[] = $editor;
|
||||
$active_editors = array_unique($active_editors);
|
||||
add_to_config_log('editor_visibility', '0', '1', $editor);
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('editor');
|
||||
$class::enable_plugin($editor, true);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -68,6 +65,8 @@ switch ($action) {
|
||||
$active_editors[$key] = $active_editors[$key + 1];
|
||||
$active_editors[$key + 1] = $fsave;
|
||||
add_to_config_log('editor_position', $key, $key + 1, $editor);
|
||||
set_config('texteditors', implode(',', $active_editors));
|
||||
core_plugin_manager::reset_caches();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -82,6 +81,8 @@ switch ($action) {
|
||||
$active_editors[$key] = $active_editors[$key - 1];
|
||||
$active_editors[$key - 1] = $fsave;
|
||||
add_to_config_log('editor_position', $key, $key - 1, $editor);
|
||||
set_config('texteditors', implode(',', $active_editors));
|
||||
core_plugin_manager::reset_caches();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -90,14 +91,6 @@ switch ($action) {
|
||||
break;
|
||||
}
|
||||
|
||||
// at least one editor must be active
|
||||
if (empty($active_editors)) {
|
||||
$active_editors = array('textarea');
|
||||
}
|
||||
|
||||
set_config('texteditors', implode(',', $active_editors));
|
||||
core_plugin_manager::reset_caches();
|
||||
|
||||
if ($return) {
|
||||
redirect ($returnurl);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user