Merge branch 'MDL-32657-master-1' of git://git.luns.net.uk/moodle
[moodle.git] / lib / form / textarea.php
blobd3719b1aa65f6b68a0759adaa92535e2564ffbe3
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Textarea type form element
21 * Contains HTML class for a textarea type element
23 * @package core_form
24 * @copyright 2006 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once('HTML/QuickForm/textarea.php');
30 /**
31 * Textarea type form element
33 * HTML class for a textarea type element
35 * @package core_form
36 * @category form
37 * @copyright 2006 Jamie Pratt <me@jamiep.org>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class MoodleQuickForm_textarea extends HTML_QuickForm_textarea{
41 /** @var string Need to store id of form as we may need it for helpbutton */
42 var $_formid = '';
44 /** @var string html for help button, if empty then no help */
45 var $_helpbutton='';
47 /** @var bool if true label will be hidden */
48 var $_hiddenLabel=false;
50 /**
51 * constructor
53 * @param string $elementName (optional) name of the text field
54 * @param string $elementLabel (optional) text field label
55 * @param string $attributes (optional) Either a typical HTML attribute string or an associative array
57 function MoodleQuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null) {
58 parent::HTML_QuickForm_textarea($elementName, $elementLabel, $attributes);
61 /**
62 * set html for help button
64 * @param array $helpbuttonargs array of arguments to make a help button
65 * @param string $function function name to call to get html
66 * @deprecated since Moodle 2.0. Please do not call this function any more.
67 * @todo MDL-31047 this api will be removed.
68 * @see MoodleQuickForm::setHelpButton()
70 function setHelpButton($helpbuttonargs, $function='helpbutton'){
71 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
74 /**
75 * get html for help button
77 * @return string html for help button
79 function getHelpButton(){
80 return $this->_helpbutton;
83 /**
84 * Sets label to be hidden
86 * @param bool $hiddenLabel sets if label should be hidden
88 function setHiddenLabel($hiddenLabel){
89 $this->_hiddenLabel = $hiddenLabel;
92 /**
93 * Returns HTML for this form element.
95 * @return string
97 function toHtml(){
98 if ($this->_hiddenLabel){
99 $this->_generateId();
100 return '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' .
101 $this->getLabel() . '</label>' . parent::toHtml();
102 } else {
103 return parent::toHtml();
108 * Called by HTML_QuickForm whenever form event is made on this element
110 * @param string $event Name of event
111 * @param mixed $arg event arguments
112 * @param object $caller calling object
114 function onQuickFormEvent($event, $arg, &$caller)
116 switch ($event) {
117 case 'createElement':
118 $this->_formid = $caller->getAttribute('id');
119 break;
121 return parent::onQuickFormEvent($event, $arg, $caller);
125 * Slightly different container template when frozen.
127 * @return string
129 function getElementTemplateType(){
130 if ($this->_flagFrozen){
131 return 'static';
132 } else {
133 return 'default';