[TASK] Make TYPO3 Core PSR-2 standard compliant
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Form / TextareaViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * Textarea view helper.
16 * The value of the text area needs to be set via the "value" attribute, as with all other form ViewHelpers.
17 *
18 * = Examples =
19 *
20 * <code title="Example">
21 * <f:form.textarea name="myTextArea" value="This is shown inside the textarea" />
22 * </code>
23 * <output>
24 * <textarea name="myTextArea">This is shown inside the textarea</textarea>
25 * </output>
26 *
27 * @api
28 */
29 class TextareaViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
30 {
31 /**
32 * @var string
33 */
34 protected $tagName = 'textarea';
35
36 /**
37 * Initialize the arguments.
38 *
39 * @return void
40 * @api
41 */
42 public function initializeArguments()
43 {
44 parent::initializeArguments();
45 $this->registerTagAttribute('autofocus', 'string', 'Specifies that a text area should automatically get focus when the page loads');
46 $this->registerTagAttribute('rows', 'int', 'The number of rows of a text area');
47 $this->registerTagAttribute('cols', 'int', 'The number of columns of a text area');
48 $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
49 $this->registerTagAttribute('placeholder', 'string', 'The placeholder of the textarea');
50 $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this view helper', false, 'f3-form-error');
51 $this->registerUniversalTagAttributes();
52 }
53
54 /**
55 * Renders the textarea.
56 *
57 * @return string
58 * @api
59 */
60 public function render()
61 {
62 $name = $this->getName();
63 $this->registerFieldNameForFormTokenGeneration($name);
64 $this->setRespectSubmittedDataValue(true);
65
66 $this->tag->forceClosingTag(true);
67 $this->tag->addAttribute('name', $name);
68 $this->tag->setContent(htmlspecialchars($this->getValueAttribute()));
69
70 $this->addAdditionalIdentityPropertiesIfNeeded();
71 $this->setErrorClassAttribute();
72
73 return $this->tag->render();
74 }
75 }