NOBUG: Fixed file access permissions
[moodle.git] / lib / form / textarea.php
blobe8b7682ce47e4b74e4e9672bbd3f9a71d39cfee4
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');
29 require_once('templatable_form_element.php');
31 /**
32 * Textarea type form element
34 * HTML class for a textarea type element
36 * @package core_form
37 * @category form
38 * @copyright 2006 Jamie Pratt <me@jamiep.org>
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class MoodleQuickForm_textarea extends HTML_QuickForm_textarea implements templatable {
42 use templatable_form_element {
43 export_for_template as export_for_template_base;
46 /** @var string Need to store id of form as we may need it for helpbutton */
47 var $_formid = '';
49 /** @var string html for help button, if empty then no help */
50 var $_helpbutton='';
52 /** @var bool if true label will be hidden */
53 var $_hiddenLabel=false;
55 /** @var bool Whether to force the display of this element to flow LTR. */
56 protected $forceltr = false;
58 /**
59 * constructor
61 * @param string $elementName (optional) name of the text field
62 * @param string $elementLabel (optional) text field label
63 * @param string $attributes (optional) Either a typical HTML attribute string or an associative array
65 public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
66 parent::__construct($elementName, $elementLabel, $attributes);
69 /**
70 * Old syntax of class constructor. Deprecated in PHP7.
72 * @deprecated since Moodle 3.1
74 public function MoodleQuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null) {
75 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
76 self::__construct($elementName, $elementLabel, $attributes);
79 /**
80 * get html for help button
82 * @return string html for help button
84 function getHelpButton(){
85 return $this->_helpbutton;
88 /**
89 * Sets label to be hidden
91 * @param bool $hiddenLabel sets if label should be hidden
93 function setHiddenLabel($hiddenLabel){
94 $this->_hiddenLabel = $hiddenLabel;
97 /**
98 * Returns HTML for this form element.
100 * @return string
102 function toHtml(){
104 // Add the class at the last minute.
105 if ($this->get_force_ltr()) {
106 if (!isset($this->_attributes['class'])) {
107 $this->_attributes['class'] = 'text-ltr';
108 } else {
109 $this->_attributes['class'] .= ' text-ltr';
113 if ($this->_hiddenLabel){
114 $this->_generateId();
115 return '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' .
116 $this->getLabel() . '</label>' . parent::toHtml();
117 } else {
118 return parent::toHtml();
123 * Called by HTML_QuickForm whenever form event is made on this element
125 * @param string $event Name of event
126 * @param mixed $arg event arguments
127 * @param object $caller calling object
129 function onQuickFormEvent($event, $arg, &$caller)
131 switch ($event) {
132 case 'createElement':
133 $this->_formid = $caller->getAttribute('id');
134 break;
136 return parent::onQuickFormEvent($event, $arg, $caller);
140 * Slightly different container template when frozen.
142 * @return string
144 function getElementTemplateType(){
145 if ($this->_flagFrozen){
146 return 'static';
147 } else {
148 return 'default';
153 * Get force LTR option.
155 * @return bool
157 public function get_force_ltr() {
158 return $this->forceltr;
162 * Force the field to flow left-to-right.
164 * This is useful for fields such as code or configuration snippets.
166 * @param bool $value The value to set the option to.
168 public function set_force_ltr($value) {
169 $this->forceltr = (bool) $value;
172 public function export_for_template(renderer_base $output) {
173 $context = $this->export_for_template_base($output);
174 $context['value'] = $this->getValue();
176 return $context;