TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
RadioViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
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 
62  public function initializeArguments()
63  {
64  parent::initializeArguments();
65  $this->registerArgument(
66  'errorClass', 'string', 'CSS class to set if there are errors for this view helper', false, 'f3-form-error'
67  );
68  $this->registerArgument('checked', 'bool', 'Specifies that the input element should be preselected');
69  $this->overrideArgument('value', 'string', 'Value of input tag. Required for radio buttons', true);
71  $this->registerTagAttribute(
72  'disabled', 'string', 'Specifies that the input element should be disabled when the page loads'
73  );
74  }
75 
82  public function render()
83  {
84  $checked = $this->arguments['checked'];
85 
86  $this->tag->addAttribute('type', 'radio');
87 
88  $nameAttribute = $this->getName();
89  $valueAttribute = $this->getValueAttribute();
90 
91  $propertyValue = null;
92  if ($this->hasMappingErrorOccurred()) {
93  $propertyValue = $this->getLastSubmittedFormData();
94  }
95  if ($checked === null && $propertyValue === null) {
96  $propertyValue = $this->getPropertyValue();
97  $propertyValue = $this->convertToPlainValue($propertyValue);
98  }
99 
100  if ($propertyValue !== null) {
101  // no type-safe comparison by intention
102  $checked = $propertyValue == $valueAttribute;
103  }
104 
105  $this->registerFieldNameForFormTokenGeneration($nameAttribute);
106  $this->tag->addAttribute('name', $nameAttribute);
107  $this->tag->addAttribute('value', $valueAttribute);
108  if ($checked === true) {
109  $this->tag->addAttribute('checked', 'checked');
110  }
111 
112  $this->setErrorClassAttribute();
113 
114  return $this->tag->render();
115  }
116 }
registerTagAttribute($name, $type, $description, $required=false, $default=null)