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