MDL-9137 Fixing errors in the overview report
[moodle-pu.git] / lib / form / format.php
blob7fad587b2d2bcc5005e1741c10f656bd4efbea60
1 <?php
2 global $CFG;
3 require_once "$CFG->libdir/form/select.php";
5 /**
6 * HTML class for a editor format drop down element
8 * @author Jamie Pratt
9 * @access public
11 class MoodleQuickForm_format extends MoodleQuickForm_select{
13 /**
14 * Whether we are using html editor.
16 * @var unknown_type
18 var $_useHtmlEditor;
19 /**
20 * Class constructor
22 * @param string Select name attribute
23 * @param mixed Label(s) for the select
24 * @param mixed Either a typical HTML attribute string or an associative array
25 * @param mixed Either a string returned from can_use_html_editor() or false for no html editor
26 * default 'detect' tells element to use html editor if it is available.
27 * @access public
28 * @return void
30 function MoodleQuickForm_format($elementName=null, $elementLabel=null, $attributes=null, $useHtmlEditor=null)
32 if ($elementName == null){
33 $elementName = 'format';
35 if ($elementLabel == null){
36 $elementLabel = get_string('format');
38 HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
39 $this->_type = 'format';
41 $this->_useHtmlEditor=$useHtmlEditor;
42 if ($this->_useHtmlEditor === null){
43 $this->_useHtmlEditor=can_use_html_editor();
46 $this->setPersistantFreeze($this->_useHtmlEditor);
47 if ($this->_useHtmlEditor){
48 $this->freeze();
49 } else {
50 $this->unfreeze();
52 } //end constructor
54 /**
55 * Called by HTML_QuickForm whenever form event is made on this element
57 * @param string $event Name of event
58 * @param mixed $arg event arguments
59 * @param object $caller calling object
60 * @since 1.0
61 * @access public
62 * @return mixed
64 function onQuickFormEvent($event, $arg, &$caller)
66 switch ($event) {
67 case 'createElement':
68 $this->load(format_text_menu());
69 $this->setHelpButton(array('textformat', get_string('helpformatting')));
70 break;
71 case 'updateValue' :
72 $value = $this->_findValue($caller->_constantValues);
73 if (null === $value) {
74 $value = $this->_findValue($caller->_submitValues);
75 // Fix for bug #4465 & #5269
76 // XXX: should we push this to element::onQuickFormEvent()?
77 if (null === $value && (!$caller->isSubmitted() || !$this->getMultiple())) {
78 $value = $this->_findValue($caller->_defaultValues);
81 if (null !== $value) {
82 $format=$value;
83 }else{
84 $format=FORMAT_MOODLE;
86 if ($this->_useHtmlEditor){
87 $this->setValue(array(FORMAT_HTML));
88 }else{
89 $this->setValue(array($format));
91 return true;
92 break;
94 return parent::onQuickFormEvent($event, $arg, $caller);