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