Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
textarea.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Form
5  *
6  * @copyright Copyright (C) 2005 - 2013 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  * @package Joomla.Platform
17  * @subpackage Form
18  * @link http://www.w3.org/TR/html-markup/textarea.html#textarea
19  * @since 11.1
20  */
22 {
23  /**
24  * The form field type.
25  *
26  * @var string
27  * @since 11.1
28  */
29  protected $type = 'Textarea';
30 
31  /**
32  * The number of rows in textarea.
33  *
34  * @var mixed
35  * @since 3.2
36  */
37  protected $rows;
38 
39  /**
40  * The number of columns in textarea.
41  *
42  * @var mixed
43  * @since 3.2
44  */
45  protected $columns;
46 
47  /**
48  * Method to get certain otherwise inaccessible properties from the form field object.
49  *
50  * @param string $name The property name for which to the the value.
51  *
52  * @return mixed The property value or null.
53  *
54  * @since 3.2
55  */
56  public function __get($name)
57  {
58  switch ($name)
59  {
60  case 'rows':
61  case 'columns':
62  return $this->$name;
63  }
64 
65  return parent::__get($name);
66  }
67 
68  /**
69  * Method to set certain otherwise inaccessible properties of the form field object.
70  *
71  * @param string $name The property name for which to the the value.
72  * @param mixed $value The value of the property.
73  *
74  * @return void
75  *
76  * @since 3.2
77  */
78  public function __set($name, $value)
79  {
80  switch ($name)
81  {
82  case 'rows':
83  case 'columns':
84  $this->name = (int) $value;
85  break;
86 
87  default:
88  parent::__set($name, $value);
89  }
90  }
91 
92  /**
93  * Method to attach a JForm object to the field.
94  *
95  * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
96  * @param mixed $value The form field value to validate.
97  * @param string $group The field name group control value. This acts as as an array container for the field.
98  * For example if the field has name="foo" and the group value is set to "bar" then the
99  * full field name would end up being "bar[foo]".
100  *
101  * @return boolean True on success.
102  *
103  * @see JFormField::setup()
104  * @since 3.2
105  */
106  public function setup(SimpleXMLElement $element, $value, $group = null)
107  {
108  $return = parent::setup($element, $value, $group);
109 
110  if ($return)
111  {
112  $this->rows = isset($this->element['rows']) ? (int) $this->element['rows'] : false;
113  $this->columns = isset($this->element['cols']) ? (int) $this->element['cols'] : false;
114  }
115 
116  return $return;
117  }
118 
119  /**
120  * Method to get the textarea field input markup.
121  * Use the rows and columns attributes to specify the dimensions of the area.
122  *
123  * @return string The field input markup.
124  *
125  * @since 11.1
126  */
127  protected function getInput()
128  {
129  // Translate placeholder text
130  $hint = $this->translateHint ? JText::_($this->hint) : $this->hint;
131 
132  // Initialize some field attributes.
133  $class = !empty($this->class) ? ' class="' . $this->class . '"' : '';
134  $disabled = $this->disabled ? ' disabled' : '';
135  $readonly = $this->readonly ? ' readonly' : '';
136  $columns = $this->columns ? ' cols="' . $this->columns . '"' : '';
137  $rows = $this->rows ? ' rows="' . $this->rows . '"' : '';
138  $required = $this->required ? ' required aria-required="true"' : '';
139  $hint = $hint ? ' placeholder="' . $hint . '"' : '';
140  $autocomplete = !$this->autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $this->autocomplete . '"';
141  $autocomplete = $autocomplete == ' autocomplete="on"' ? '' : $autocomplete;
142  $autofocus = $this->autofocus ? ' autofocus' : '';
143  $spellcheck = $this->spellcheck ? '' : ' spellcheck="false"';
144 
145  // Initialize JavaScript field attributes.
146  $onchange = $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
147  $onclick = $this->onclick ? ' onclick="' . $this->onclick . '"' : '';
148 
149  // Including fallback code for HTML5 non supported browsers.
150  JHtml::_('jquery.framework');
151  JHtml::_('script', 'system/html5fallback.js', false, true);
152 
153  return '<textarea name="' . $this->name . '" id="' . $this->id . '"' . $columns . $rows . $class
154  . $hint . $disabled . $readonly . $onchange . $onclick . $required . $autocomplete . $autofocus . $spellcheck . ' >'
155  . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>';
156  }
157 }