‪TYPO3CMS  10.4
RadioViewHelper.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 
64 {
68  protected ‪$tagName = 'input';
69 
73  public function ‪initializeArguments()
74  {
75  parent::initializeArguments();
76  $this->registerArgument(
77  'errorClass',
78  'string',
79  'CSS class to set if there are errors for this ViewHelper',
80  false,
81  'f3-form-error'
82  );
83  $this->registerArgument('checked', 'bool', 'Specifies that the input element should be preselected');
84  $this->overrideArgument('value', 'string', 'Value of input tag. Required for radio buttons', true);
85  $this->registerUniversalTagAttributes();
86  $this->registerTagAttribute(
87  'disabled',
88  'string',
89  'Specifies that the input element should be disabled when the page loads'
90  );
91  }
92 
98  public function ‪render()
99  {
100  $checked = $this->arguments['checked'];
101 
102  $this->tag->addAttribute('type', 'radio');
103 
104  $nameAttribute = $this->‪getName();
105  $valueAttribute = $this->‪getValueAttribute();
106 
107  $propertyValue = null;
108  if ($this->‪hasMappingErrorOccurred()) {
109  $propertyValue = $this->‪getLastSubmittedFormData();
110  }
111  if ($checked === null && $propertyValue === null) {
112  $propertyValue = $this->‪getPropertyValue();
113  $propertyValue = $this->‪convertToPlainValue($propertyValue);
114  }
115 
116  if ($propertyValue !== null) {
117  // no type-safe comparison by intention
118  $checked = $propertyValue == $valueAttribute;
119  }
120 
121  $this->‪registerFieldNameForFormTokenGeneration($nameAttribute);
122  $this->tag->addAttribute('name', $nameAttribute);
123  $this->tag->addAttribute('value', $valueAttribute);
124  if ($checked === true) {
125  $this->tag->addAttribute('checked', 'checked');
126  }
127 
128  $this->‪setErrorClassAttribute();
129 
130  return $this->tag->render();
131  }
132 }
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\setErrorClassAttribute
‪setErrorClassAttribute()
Definition: AbstractFormFieldViewHelper.php:331
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper\render
‪string render()
Definition: RadioViewHelper.php:97
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\convertToPlainValue
‪mixed convertToPlainValue($value)
Definition: AbstractFormFieldViewHelper.php:202
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getPropertyValue
‪mixed getPropertyValue()
Definition: AbstractFormFieldViewHelper.php:295
‪TYPO3\CMS\Fluid\ViewHelpers\Form
Definition: AbstractFormFieldViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getLastSubmittedFormData
‪mixed getLastSubmittedFormData()
Definition: AbstractFormFieldViewHelper.php:229
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper
Definition: RadioViewHelper.php:64
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\registerFieldNameForFormTokenGeneration
‪registerFieldNameForFormTokenGeneration($fieldName)
Definition: AbstractFormViewHelper.php:106
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper\$tagName
‪string $tagName
Definition: RadioViewHelper.php:67
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper\initializeArguments
‪initializeArguments()
Definition: RadioViewHelper.php:72
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
Definition: AbstractFormFieldViewHelper.php:30
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\hasMappingErrorOccurred
‪bool hasMappingErrorOccurred()
Definition: AbstractFormFieldViewHelper.php:218
‪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