MDL-19211 back to the old text format preferences logic + minor refactoring and improvements
This commit is contained in:
+1
-69
@@ -10,12 +10,6 @@ require_once "$CFG->libdir/form/select.php";
|
||||
*/
|
||||
class MoodleQuickForm_format extends MoodleQuickForm_select{
|
||||
|
||||
/**
|
||||
* Whether we are using html editor.
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $_useHtmlEditor;
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
@@ -29,69 +23,7 @@ class MoodleQuickForm_format extends MoodleQuickForm_select{
|
||||
*/
|
||||
function MoodleQuickForm_format($elementName=null, $elementLabel=null, $attributes=null, $useHtmlEditor=null)
|
||||
{
|
||||
if ($elementName == null){
|
||||
$elementName = 'format';
|
||||
}
|
||||
if ($elementLabel == null){
|
||||
$elementLabel = get_string('format');
|
||||
}
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_type = 'format';
|
||||
|
||||
$this->_useHtmlEditor=$useHtmlEditor;
|
||||
if ($this->_useHtmlEditor === null){
|
||||
$this->_useHtmlEditor=can_use_html_editor();
|
||||
}
|
||||
|
||||
$this->setPersistantFreeze($this->_useHtmlEditor);
|
||||
if ($this->_useHtmlEditor){
|
||||
$this->freeze();
|
||||
} else {
|
||||
$this->unfreeze();
|
||||
}
|
||||
throw new coding_error('MFORMS: Coding error, text formats are handled only by new editor element.');
|
||||
} //end constructor
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'createElement':
|
||||
$menu = format_text_menu();
|
||||
$this->load($menu);
|
||||
break;
|
||||
case 'updateValue' :
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
// Fix for bug #4465 & #5269
|
||||
// XXX: should we push this to element::onQuickFormEvent()?
|
||||
if (null === $value && (!$caller->isSubmitted() || !$this->getMultiple())) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$format=$value;
|
||||
}else{
|
||||
$format=FORMAT_MOODLE;
|
||||
}
|
||||
if ($this->_useHtmlEditor){
|
||||
$this->setValue(array(FORMAT_HTML));
|
||||
}else{
|
||||
$this->setValue(array($format));
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user