MDL-11113 completely reimplemented editor plugin settings - we should never use custom forms instead of admin settings if possible

This commit is contained in:
Petr Skoda 2010-07-04 20:53:01 +00:00
parent 09ae4cad1a
commit 6fc67fce72
4 changed files with 34 additions and 63 deletions

View file

@ -17,7 +17,6 @@ $action = optional_param('action', '', PARAM_ACTION);
$editor = optional_param('editor', '', PARAM_SAFEDIR); $editor = optional_param('editor', '', PARAM_SAFEDIR);
// get currently installed and enabled auth plugins // get currently installed and enabled auth plugins
$settingsurl = "$CFG->wwwroot/$CFG->admin/editors.php?sesskey=".sesskey()."&action=edit&editor=$editor";
$available_editors = get_available_editors(); $available_editors = get_available_editors();
if (!empty($editor) and empty($available_editors[$editor])) { if (!empty($editor) and empty($available_editors[$editor])) {
redirect ($returnurl); redirect ($returnurl);
@ -79,45 +78,6 @@ switch ($action) {
} }
} }
break; break;
case 'edit':
$form_file = $CFG->dirroot . '/lib/editor/'.$editor.'/settings.php';
if (file_exists($form_file)) {
require_once($form_file);
$classname = 'editor_settings_' . $editor;
$pagename = 'editorsettings' . $editor;
admin_externalpage_setup($pagename);
$form = new $classname();
$options = call_user_func($classname . '::option_names');
$data = $form->get_data();
if ($form->is_cancelled()){
// do nothing
} else if (!empty($data)) {
foreach ($data as $key=>$value) {
// editor options must be started with 'editor_'
if (strpos($key, 'editor_') === 0 && in_array($key, $options)) {
set_config($key, $value, 'editor');
}
}
} else {
$data = array();
foreach ($options as $key) {
$data[$key] = get_config('editor', $key);
}
$form->set_data($data);
$PAGE->set_pagetype('admin-editors-' . $editor);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('pluginname', 'editor_'.$editor));
$OUTPUT->box_start();
$form->display();
$OUTPUT->box_end();
echo $OUTPUT->footer();
$return = false;
}
}
break;
default: default:
break; break;
} }

View file

@ -136,13 +136,17 @@ if ($hassiteconfig) {
$ADMIN->add('editorsettings', $temp); $ADMIN->add('editorsettings', $temp);
$editors_available = get_available_editors(); $editors_available = get_available_editors();
$url = $CFG->wwwroot.'/'.$CFG->admin.'/editors.php?sesskey='.sesskey();
foreach ($editors_available as $editor=>$editorstr) { foreach ($editors_available as $editor=>$editorstr) {
if (file_exists($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php')) { if (file_exists($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php')) {
$editor_setting = new admin_externalpage('editorsettings'.$editor, $editorstr, $url.'&action=edit&editor='.$editor); $settings = new admin_settingpage('editorsettings'.$editor, get_string('pluginname', 'editor_'.$editor), 'moodle/site:config');
$ADMIN->add('editorsettings', $editor_setting); // 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);
}
} }
} }
/// License types /// License types
$ADMIN->add('modules', new admin_category('licensesettings', get_string('license'))); $ADMIN->add('modules', new admin_category('licensesettings', get_string('license')));
$temp = new admin_settingpage('managelicenses', get_string('license')); $temp = new admin_settingpage('managelicenses', get_string('license'));

View file

@ -5286,7 +5286,8 @@ class admin_setting_manageeditors extends admin_setting {
// settings link // settings link
if (file_exists($CFG->dirroot.'/lib/editor/'.$editor.'/settings.php')) { if (file_exists($CFG->dirroot.'/lib/editor/'.$editor.'/settings.php')) {
$settings = "<a href='$url&amp;editor=$editor&amp;action=edit'>{$txt->settings}</a>"; $eurl = new moodle_url('/admin/settings.php', array('section'=>'editorsettingstinymce'));
$settings = "<a href='$eurl'>{$txt->settings}</a>";
} else { } else {
$settings = ''; $settings = '';
} }

View file

@ -1,29 +1,35 @@
<?php <?php
//TODO: this is very wrong way to do admin settings - this has to be rewritten!! // This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* TinyMCE editor settings moodle form class. * TinyMCE admin settings
* *
* @package editor_tinymce * @package editor_tinymce
* @copyright 2010 Dongsheng Cai * @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class editor_settings_tinymce extends editor_settings_form {
public function definition() {
$mform = $this->_form;
$options = array(
'PSpell'=>'PSpell',
'GoogleSpell'=>'Google Spell',
'PSpellShell'=>'PSpellShell');
// options must be started with editor_ to get stored
$mform->addElement('select', 'editor_tinymce_spellengine', get_string('spellengine', 'admin'), $options);
$mform->addElement('hidden', 'editor', 'tinymce');
parent::definition(); defined('MOODLE_INTERNAL') || die;
}
static public function option_names() { if ($ADMIN->fulltree) {
return array('editor_tinymce_spellengine'); $options = array(
} 'PSpell'=>'PSpell',
'GoogleSpell'=>'Google Spell',
'PSpellShell'=>'PSpellShell');
$settings->add(new admin_setting_configselect('editor_tinymce/spellengine', get_string('spellengine', 'admin'), '', 'GoogleSpell', $options));
} }