‪TYPO3CMS  11.5
TextfieldViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
33 {
37  protected ‪$tagName = 'input';
38 
44  public function ‪initializeArguments()
45  {
46  parent::initializeArguments();
47  $this->registerTagAttribute('autofocus', 'string', 'Specifies that an input should automatically get focus when the page loads');
48  $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
49  $this->registerTagAttribute('maxlength', 'int', 'The maxlength attribute of the input field (will not be validated)');
50  $this->registerTagAttribute('readonly', 'string', 'The readonly attribute of the input field');
51  $this->registerTagAttribute('size', 'int', 'The size of the input field');
52  $this->registerTagAttribute('placeholder', 'string', 'The placeholder of the textfield');
53  $this->registerTagAttribute('pattern', 'string', 'HTML5 validation pattern');
54  $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this ViewHelper', false, 'f3-form-error');
55  $this->registerUniversalTagAttributes();
56  $this->registerArgument('required', 'bool', 'If the field is required or not', false, false);
57  $this->registerArgument('type', 'string', 'The field type, e.g. "text", "email", "url" etc.', false, 'text');
58  }
59 
65  public function ‪render()
66  {
67  $required = $this->arguments['required'] ?? false;
68  $type = $this->arguments['type'] ?? null;
69 
70  $name = $this->‪getName();
73 
74  $this->tag->addAttribute('type', $type);
75  $this->tag->addAttribute('name', $name);
76 
77  $value = $this->‪getValueAttribute();
78 
79  if ($value !== null) {
80  $this->tag->addAttribute('value', $value);
81  }
82 
83  if ($required !== false) {
84  $this->tag->addAttribute('required', 'required');
85  }
86 
89 
90  return $this->tag->render();
91  }
92 }
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\setErrorClassAttribute
‪setErrorClassAttribute()
Definition: AbstractFormFieldViewHelper.php:331
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\setRespectSubmittedDataValue
‪setRespectSubmittedDataValue($respectSubmittedDataValue)
Definition: AbstractFormFieldViewHelper.php:77
‪TYPO3\CMS\Fluid\ViewHelpers\Form
Definition: AbstractFormFieldViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper\initializeArguments
‪initializeArguments()
Definition: TextfieldViewHelper.php:43
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper\render
‪string render()
Definition: TextfieldViewHelper.php:64
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\registerFieldNameForFormTokenGeneration
‪registerFieldNameForFormTokenGeneration($fieldName)
Definition: AbstractFormViewHelper.php:106
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper
Definition: TextfieldViewHelper.php:33
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
Definition: AbstractFormFieldViewHelper.php:30
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\addAdditionalIdentityPropertiesIfNeeded
‪addAdditionalIdentityPropertiesIfNeeded()
Definition: AbstractFormFieldViewHelper.php:243
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getName
‪string getName()
Definition: AbstractFormFieldViewHelper.php:90
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getValueAttribute
‪mixed getValueAttribute()
Definition: AbstractFormFieldViewHelper.php:151
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper\$tagName
‪string $tagName
Definition: TextfieldViewHelper.php:36