TYPO3 CMS  TYPO3_8-7
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 
50 {
54  protected $tagName = 'input';
55 
61  public function initializeArguments()
62  {
63  parent::initializeArguments();
64  $this->registerArgument(
65  'errorClass',
66  'string',
67  'CSS class to set if there are errors for this view helper',
68  false,
69  'f3-form-error'
70  );
71  $this->registerArgument('checked', 'bool', 'Specifies that the input element should be preselected');
72  $this->overrideArgument('value', 'string', 'Value of input tag. Required for radio buttons', true);
74  $this->registerTagAttribute(
75  'disabled',
76  'string',
77  'Specifies that the input element should be disabled when the page loads'
78  );
79  }
80 
87  public function render()
88  {
89  $checked = $this->arguments['checked'];
90 
91  $this->tag->addAttribute('type', 'radio');
92 
93  $nameAttribute = $this->getName();
94  $valueAttribute = $this->getValueAttribute();
95 
96  $propertyValue = null;
97  if ($this->hasMappingErrorOccurred()) {
98  $propertyValue = $this->getLastSubmittedFormData();
99  }
100  if ($checked === null && $propertyValue === null) {
101  $propertyValue = $this->getPropertyValue();
102  $propertyValue = $this->convertToPlainValue($propertyValue);
103  }
104 
105  if ($propertyValue !== null) {
106  // no type-safe comparison by intention
107  $checked = $propertyValue == $valueAttribute;
108  }
109 
110  $this->registerFieldNameForFormTokenGeneration($nameAttribute);
111  $this->tag->addAttribute('name', $nameAttribute);
112  $this->tag->addAttribute('value', $valueAttribute);
113  if ($checked === true) {
114  $this->tag->addAttribute('checked', 'checked');
115  }
116 
117  $this->setErrorClassAttribute();
118 
119  return $this->tag->render();
120  }
121 }
registerTagAttribute($name, $type, $description, $required=false, $default=null)