TYPO3 CMS  TYPO3_7-6
RadioViewHelper.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /* *
6  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
7  * *
8  * It is free software; you can redistribute it and/or modify it under *
9  * the terms of the GNU Lesser General Public License, either version 3 *
10  * of the License, or (at your option) any later version. *
11  * *
12  * The TYPO3 project - inspiring people to share! *
13  * */
14 
48 {
52  protected $tagName = 'input';
53 
60  public function initializeArguments()
61  {
62  parent::initializeArguments();
63  $this->registerTagAttribute(
64  'disabled', 'string', 'Specifies that the input element should be disabled when the page loads'
65  );
66  $this->registerArgument(
67  'errorClass', 'string', 'CSS class to set if there are errors for this view helper', false, 'f3-form-error'
68  );
69  $this->overrideArgument('value', 'string', 'Value of input tag. Required for radio buttons', true);
71  }
72 
80  public function render($checked = null)
81  {
82  $this->tag->addAttribute('type', 'radio');
83 
84  $nameAttribute = $this->getName();
85  $valueAttribute = $this->getValueAttribute();
86 
87  $propertyValue = null;
88  if ($this->hasMappingErrorOccurred()) {
89  $propertyValue = $this->getLastSubmittedFormData();
90  }
91  if ($checked === null && $propertyValue === null) {
92  $propertyValue = $this->getPropertyValue();
93  $propertyValue = $this->convertToPlainValue($propertyValue);
94  }
95 
96  if ($propertyValue !== null) {
97 
98  // no type-safe comparison by intention
99  $checked = $propertyValue == $valueAttribute;
100  }
101 
102  $this->registerFieldNameForFormTokenGeneration($nameAttribute);
103  $this->tag->addAttribute('name', $nameAttribute);
104  $this->tag->addAttribute('value', $valueAttribute);
105  if ($checked === true) {
106  $this->tag->addAttribute('checked', 'checked');
107  }
108 
109  $this->setErrorClassAttribute();
110 
111  return $this->tag->render();
112  }
113 }
registerArgument($name, $type, $description, $required=false, $defaultValue=null)
registerTagAttribute($name, $type, $description, $required=false, $default=null)
overrideArgument($name, $type, $description, $required=false, $defaultValue=null)