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 $menu = format_text_menu();
70 $this->setHelpButton(array('textformat', get_string('helpformatting')));
73 $value = $this->_findValue($caller->_constantValues
);
74 if (null === $value) {
75 $value = $this->_findValue($caller->_submitValues
);
76 // Fix for bug #4465 & #5269
77 // XXX: should we push this to element::onQuickFormEvent()?
78 if (null === $value && (!$caller->isSubmitted() ||
!$this->getMultiple())) {
79 $value = $this->_findValue($caller->_defaultValues
);
82 if (null !== $value) {
85 $format=FORMAT_MOODLE
;
87 if ($this->_useHtmlEditor
){
88 $this->setValue(array(FORMAT_HTML
));
90 $this->setValue(array($format));
95 return parent
::onQuickFormEvent($event, $arg, $caller);