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