]> git.mjollnir.org Git - moodle.git/commitdiff
added new form element class 'format' for adding format drop down box to forms.
authorjamiesensei <jamiesensei>
Thu, 26 Oct 2006 07:02:20 +0000 (07:02 +0000)
committerjamiesensei <jamiesensei>
Thu, 26 Oct 2006 07:02:20 +0000 (07:02 +0000)
lib/form/format.php [new file with mode: 0644]
lib/formslib.php

diff --git a/lib/form/format.php b/lib/form/format.php
new file mode 100644 (file)
index 0000000..53cc039
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+global $CFG;
+require_once "$CFG->libdir/form/select.php";
+
+/**
+ * HTML class for a editor format drop down element
+ *
+ * @author       Jamie Pratt
+ * @access       public
+ */
+class MoodleQuickForm_format extends MoodleQuickForm_select{
+
+    /**
+     * Whether we are using html editor.
+     *
+     * @var unknown_type
+     */
+    var $_useHtmlEditor;
+    /**
+     * Class constructor
+     *
+     * @param     string    Select name attribute
+     * @param     mixed     Label(s) for the select
+     * @param     mixed     Either a typical HTML attribute string or an associative array
+     * @param     mixed     Either a string returned from can_use_html_editor() or false for no html editor
+     *                      default 'detect' tells element to use html editor if it is available.
+     * @access    public
+     * @return    void
+     */
+    function MoodleQuickForm_format($elementName=null, $elementLabel=null, $attributes=null, $useHtmlEditor=null)
+    {
+        HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
+        $this->_persistantFreeze = true;
+        $this->_type = 'format';
+        echo $useHtmlEditor;
+        $this->_useHtmlEditor=$useHtmlEditor;
+        if ($this->_useHtmlEditor==null){
+            $this->_useHtmlEditor=can_use_html_editor();
+        }
+        if ($this->_useHtmlEditor){
+            $this->freeze();
+        }
+
+
+
+    } //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':
+                $this->load(format_text_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) {
+                    $this->setValue($value);
+                }else{
+                    if ($this->_useHtmlEditor){
+                        $this->setValue(array(FORMAT_HTML));
+
+                    }else{
+                        $this->setValue(array(FORMAT_MOODLE));
+                    }
+                }
+                return true;
+                break;
+        }
+        return parent::onQuickFormEvent($event, $arg, $caller);
+    }
+
+}
+?>
\ No newline at end of file
index 71ee51cf8cfd25b0eed3696050ac1e13de87ce26..badc2c688eba4fb32dd765963a484e26f883dd72 100644 (file)
@@ -602,6 +602,7 @@ MoodleQuickForm::registerElementType('textarea', "$CFG->libdir/form/textarea.php
 MoodleQuickForm::registerElementType('date_selector', "$CFG->libdir/form/dateselector.php", 'MoodleQuickForm_date_selector');
 MoodleQuickForm::registerElementType('date_time_selector', "$CFG->libdir/form/datetimeselector.php", 'MoodleQuickForm_date_time_selector');
 MoodleQuickForm::registerElementType('htmleditor', "$CFG->libdir/form/htmleditor.php", 'MoodleQuickForm_htmleditor');
+MoodleQuickForm::registerElementType('format', "$CFG->libdir/form/format.php", 'MoodleQuickForm_format');
 MoodleQuickForm::registerElementType('static', "$CFG->libdir/form/static.php", 'MoodleQuickForm_static');
 MoodleQuickForm::registerElementType('hidden', "$CFG->libdir/form/hidden.php", 'MoodleQuickForm_hidden');