‪TYPO3CMS  ‪main
RadioViewHelper.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 
66 {
70  protected ‪$tagName = 'input';
71 
72  public function ‪initializeArguments(): void
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 
92  public function ‪render(): string
93  {
94  $checked = $this->arguments['checked'];
95 
96  $this->tag->addAttribute('type', 'radio');
97 
98  $nameAttribute = $this->‪getName();
99  $valueAttribute = $this->‪getValueAttribute();
100 
101  $propertyValue = null;
102  if ($this->‪hasMappingErrorOccurred()) {
103  $propertyValue = $this->‪getLastSubmittedFormData();
104  }
105  if ($checked === null && $propertyValue === null) {
106  $propertyValue = $this->‪getPropertyValue();
107  $propertyValue = $this->‪convertToPlainValue($propertyValue);
108  }
109 
110  if ($propertyValue !== null) {
111  // no type-safe comparison by intention
112  $checked = $propertyValue == $valueAttribute;
113  }
114 
115  $this->‪registerFieldNameForFormTokenGeneration($nameAttribute);
116  $this->tag->addAttribute('name', $nameAttribute);
117  $this->tag->addAttribute('value', $valueAttribute);
118  if ($checked === true) {
119  $this->tag->addAttribute('checked', 'checked');
120  }
121 
122  $this->‪setErrorClassAttribute();
123 
124  return $this->tag->render();
125  }
126 }
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\setErrorClassAttribute
‪setErrorClassAttribute()
Definition: AbstractFormFieldViewHelper.php:331
‪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:296
‪TYPO3\CMS\Fluid\ViewHelpers\Form
Definition: AbstractFormFieldViewHelper.php:18
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getLastSubmittedFormData
‪mixed getLastSubmittedFormData()
Definition: AbstractFormFieldViewHelper.php:225
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper
Definition: RadioViewHelper.php:66
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\registerFieldNameForFormTokenGeneration
‪registerFieldNameForFormTokenGeneration(string $fieldName)
Definition: AbstractFormViewHelper.php:100
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper\$tagName
‪string $tagName
Definition: RadioViewHelper.php:69
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getName
‪getName()
Definition: AbstractFormFieldViewHelper.php:79
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper\initializeArguments
‪initializeArguments()
Definition: RadioViewHelper.php:71
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
Definition: AbstractFormFieldViewHelper.php:37
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\hasMappingErrorOccurred
‪hasMappingErrorOccurred()
Definition: AbstractFormFieldViewHelper.php:212
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper\render
‪render()
Definition: RadioViewHelper.php:91
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getValueAttribute
‪mixed getValueAttribute()
Definition: AbstractFormFieldViewHelper.php:147