3 require_once "$CFG->libdir/form/select.php";
6 * HTML class for a editor format drop down element
11 class MoodleQuickForm_format
extends MoodleQuickForm_select
{
14 * Whether we are using html editor.
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.
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
){
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
64 function onQuickFormEvent($event, $arg, &$caller)
68 $this->load(format_text_menu());
69 $this->setHelpButton(array('textformat', get_string('helpformatting')));
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) {
84 $format=FORMAT_MOODLE
;
86 if ($this->_useHtmlEditor
){
87 $this->setValue(array(FORMAT_HTML
));
89 $this->setValue(array($format));
94 return parent
::onQuickFormEvent($event, $arg, $caller);