Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / form / format.php
blobc2b3e0e8daa3353c338f8879dcd62c10919ff166
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 $menu = format_text_menu();
69 $this->load($menu);
70 $this->setHelpButton(array('textformat', get_string('helpformatting')));
71 break;
72 case 'updateValue' :
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) {
83 $format=$value;
84 }else{
85 $format=FORMAT_MOODLE;
87 if ($this->_useHtmlEditor){
88 $this->setValue(array(FORMAT_HTML));
89 }else{
90 $this->setValue(array($format));
92 return true;
93 break;
95 return parent::onQuickFormEvent($event, $arg, $caller);