diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 6d8f95a6a82..f415aca3abb 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -91,19 +91,9 @@ if ($hassiteconfig) { $ADMIN->add('modules', new admin_category('editorsettings', new lang_string('editors', 'editor'))); $temp = new admin_settingpage('manageeditors', new lang_string('editorsettings', 'editor')); $temp->add(new admin_setting_manageeditors()); - $htmleditors = editors_get_available(); $ADMIN->add('editorsettings', $temp); - - $editors_available = editors_get_available(); - foreach ($editors_available as $editor=>$editorstr) { - if (file_exists($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php')) { - $settings = new admin_settingpage('editorsettings'.$editor, new lang_string('pluginname', 'editor_'.$editor), 'moodle/site:config'); - // settings.php may create a subcategory or unset the settings completely - include($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php'); - if ($settings) { - $ADMIN->add('editorsettings', $settings); - } - } + foreach ($allplugins['editor'] as $editor) { + $editor->load_settings($ADMIN, 'editorsettings', $hassiteconfig); } /// License types diff --git a/lib/editor/tinymce/settings.php b/lib/editor/tinymce/settings.php index 56ee3d03fab..b216d5af446 100644 --- a/lib/editor/tinymce/settings.php +++ b/lib/editor/tinymce/settings.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die; -$ADMIN->add('editorsettings', new admin_category('editortinymce', new lang_string('pluginname', 'editor_tinymce'))); +$ADMIN->add('editorsettings', new admin_category('editortinymce', $editor->displayname, $editor->is_enabled() === false)); $settings = new admin_settingpage('editorsettingstinymce', new lang_string('settings', 'editor_tinymce')); if ($ADMIN->fulltree) { diff --git a/lib/pluginlib.php b/lib/pluginlib.php index c0a5884576f..253b87c0af3 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -2669,3 +2669,51 @@ class plugininfo_local extends plugininfo_base { } } } + +/** + * Class for HTML editors + */ +class plugininfo_editor extends plugininfo_base { + + public function get_settings_section_name() { + return 'editorsettings' . $this->name; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $editor = $this; // also can be used inside settings.php + $section = $this->get_settings_section_name(); + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } + } + + /** + * Returns the information about plugin availability + * + * True means that the plugin is enabled. False means that the plugin is + * disabled. Null means that the information is not available, or the + * plugin does not support configurable availability or the availability + * can not be changed. + * + * @return null|bool + */ + public function is_enabled() { + global $CFG; + if (empty($CFG->texteditors)) { + $CFG->texteditors = 'tinymce,textarea'; + } + if (in_array($this->name, explode(',', $CFG->texteditors))) { + return true; + } + return false; + } +}