From: jamiesensei Date: Tue, 26 Sep 2006 16:40:35 +0000 (+0000) Subject: modified api to create an htmleditor element X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5ae70385944144e0a0e8e3b785555d1c0a8816ba;p=moodle.git modified api to create an htmleditor element --- diff --git a/course/edit_form.php b/course/edit_form.php index 452a6dce38..6f020ec879 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -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(); diff --git a/lib/form/htmleditor.php b/lib/form/htmleditor.php index 7630f5b76b..0ecc1f8bed 100644 --- a/lib/form/htmleditor.php +++ b/lib/form/htmleditor.php @@ -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)/", ' ',$this->getValue()), $this->_options['course'],