1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Form
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Form Field class for the Joomla Platform.
14 * Supports a multi line area for entry of plain text
15 *
16 * @link http://www.w3.org/TR/html-markup/textarea.html#textarea
17 * @since 11.1
18 */
19 class JFormFieldTextarea extends JFormField
20 {
21 /**
22 * The form field type.
23 *
24 * @var string
25 * @since 11.1
26 */
27 protected $type = 'Textarea';
28
29 /**
30 * The number of rows in textarea.
31 *
32 * @var mixed
33 * @since 3.2
34 */
35 protected $rows;
36
37 /**
38 * The number of columns in textarea.
39 *
40 * @var mixed
41 * @since 3.2
42 */
43 protected $columns;
44
45 /**
46 * The maximum number of characters in textarea.
47 *
48 * @var mixed
49 * @since 3.4
50 */
51 protected $maxlength;
52
53 /**
54 * Name of the layout being used to render the field
55 *
56 * @var string
57 * @since 3.7
58 */
59 protected $layout = 'joomla.form.field.textarea';
60
61 /**
62 * Method to get certain otherwise inaccessible properties from the form field object.
63 *
64 * @param string $name The property name for which to the the value.
65 *
66 * @return mixed The property value or null.
67 *
68 * @since 3.2
69 */
70 public function __get($name)
71 {
72 switch ($name)
73 {
74 case 'rows':
75 case 'columns':
76 case 'maxlength':
77 return $this->$name;
78 }
79
80 return parent::__get($name);
81 }
82
83 /**
84 * Method to set certain otherwise inaccessible properties of the form field object.
85 *
86 * @param string $name The property name for which to the the value.
87 * @param mixed $value The value of the property.
88 *
89 * @return void
90 *
91 * @since 3.2
92 */
93 public function __set($name, $value)
94 {
95 switch ($name)
96 {
97 case 'rows':
98 case 'columns':
99 case 'maxlength':
100 $this->$name = (int) $value;
101 break;
102
103 default:
104 parent::__set($name, $value);
105 }
106 }
107
108 /**
109 * Method to attach a JForm object to the field.
110 *
111 * @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
112 * @param mixed $value The form field value to validate.
113 * @param string $group The field name group control value. This acts as an array container for the field.
114 * For example if the field has name="foo" and the group value is set to "bar" then the
115 * full field name would end up being "bar[foo]".
116 *
117 * @return boolean True on success.
118 *
119 * @see JFormField::setup()
120 * @since 3.2
121 */
122 public function setup(SimpleXMLElement $element, $value, $group = null)
123 {
124 $return = parent::setup($element, $value, $group);
125
126 if ($return)
127 {
128 $this->rows = isset($this->element['rows']) ? (int) $this->element['rows'] : false;
129 $this->columns = isset($this->element['cols']) ? (int) $this->element['cols'] : false;
130 $this->maxlength = isset($this->element['maxlength']) ? (int) $this->element['maxlength'] : false;
131 }
132
133 return $return;
134 }
135
136 /**
137 * Method to get the textarea field input markup.
138 * Use the rows and columns attributes to specify the dimensions of the area.
139 *
140 * @return string The field input markup.
141 *
142 * @since 11.1
143 */
144 protected function getInput()
145 {
146 // Trim the trailing line in the layout file
147 return rtrim($this->getRenderer($this->layout)->render($this->getLayoutData()), PHP_EOL);
148 }
149
150 /**
151 * Method to get the data to be passed to the layout for rendering.
152 *
153 * @return array
154 *
155 * @since 3.7
156 */
157 protected function getLayoutData()
158 {
159 $data = parent::getLayoutData();
160
161 // Initialize some field attributes.
162 $columns = $this->columns ? ' cols="' . $this->columns . '"' : '';
163 $rows = $this->rows ? ' rows="' . $this->rows . '"' : '';
164 $maxlength = $this->maxlength ? ' maxlength="' . $this->maxlength . '"' : '';
165
166 $extraData = array(
167 'maxlength' => $maxlength,
168 'rows' => $rows,
169 'columns' => $columns
170 );
171
172 return array_merge($data, $extraData);
173 }
174 }
175