]> git.mjollnir.org Git - moodle.git/commitdiff
modified api to create an htmleditor element
authorjamiesensei <jamiesensei>
Tue, 26 Sep 2006 16:40:35 +0000 (16:40 +0000)
committerjamiesensei <jamiesensei>
Tue, 26 Sep 2006 16:40:35 +0000 (16:40 +0000)
course/edit_form.php
lib/form/htmleditor.php

index 452a6dce388ba0c79dc56a0b41c903b7828e6210..6f020ec879130bb6a324d4b18c1104a44ab9e59b 100644 (file)
@@ -13,7 +13,7 @@
     $mform->addElement('text','fullname', get_string("fullname"),'maxlength="254" size="50"');
     $mform->addElement('text','shortname', get_string("shortname"),'maxlength="15" size="10"');
     $mform->addElement('text','idnumber', get_string("idnumbercourse"),'maxlength="100"  size="10"');
-    $mform->addElement('htmleditor','summary', get_string("summary"), 'width="500" height="200" rows="10", cols="40"');
+    $mform->addElement('htmleditor','summary', get_string("summary"), array('rows'=>'10', 'cols'=>'65'));
 
     $courseformats = get_list_of_plugins("course/format");
     $formcourseformats = array();
index 7630f5b76bd03edbae45ca417a913021eb296793..0ecc1f8bed9ca86952efd0281f291f8d8d29714f 100644 (file)
@@ -12,11 +12,25 @@ class moodleform_htmleditor extends moodleform_textarea{
     var $_type;
     var $_elementTemplateType='default';
     var $_canUseHtmlEditor;
-    var $_options=array('course'=>0);
-    function moodleform_htmleditor($elementName=null, $elementLabel=null, $attributes=null){
+    var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>65, 'width'=>0,'height'=>0, 'course'=>0);
+    function moodleform_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
         parent::moodleform_textarea($elementName, $elementLabel, $attributes);
-        $this->_canUseHtmlEditor=can_use_html_editor();
-        if ($this->_canUseHtmlEditor){
+        // set the options, do not bother setting bogus ones
+        if (is_array($options)) {
+            foreach ($options as $name => $value) {
+                if (isset($this->_options[$name])) {
+                    if (is_array($value) && is_array($this->_options[$name])) {
+                        $this->_options[$name] = @array_merge($this->_options[$name], $value);
+                    } else {
+                        $this->_options[$name] = $value;
+                    }
+                }
+            }
+        }
+        if ($this->_options['canUseHtmlEditor']=='detect'){
+            $this->_options['canUseHtmlEditor']=can_use_html_editor();
+        }
+        if ($this->_options['canUseHtmlEditor']){
             $this->_type='htmleditor';
             //$this->_elementTemplateType='wide';
         }else{
@@ -27,7 +41,7 @@ class moodleform_htmleditor extends moodleform_textarea{
         return $this->_elementTemplateType;
     }
     function toHtml(){
-        if ($this->_canUseHtmlEditor){
+        if ($this->_options['canUseHtmlEditor'] && !$this->_flagFrozen){
             ob_start();
             use_html_editor($this->getName());
             $script=ob_get_clean();
@@ -38,11 +52,11 @@ class moodleform_htmleditor extends moodleform_textarea{
             return $this->getFrozenHtml();
         } else {
             return $this->_getTabs() .
-                    print_textarea($this->_canUseHtmlEditor
-                                    $this->getAttribute('rows'),
-                                    $this->getAttribute('cols'),
-                                    $this->getAttribute('width'),
-                                    $this->getAttribute('height'),
+                    print_textarea($this->_options['canUseHtmlEditor']
+                                    $this->_options['rows'],
+                                    $this->_options['cols'],
+                                    $this->_options['width'],
+                                    $this->_options['height'],
                                     $this->getName(),
                                     preg_replace("/(\r\n|\n|\r)/", '&#010;',$this->getValue()),
                                     $this->_options['course'],