• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TYPO3-Headless / headless / 14022693367

23 Mar 2025 08:26PM UTC coverage: 52.345% (-20.8%) from 73.13%
14022693367

Pull #815

github

web-flow
Merge e0fcdaa4a into a15e1c8c4
Pull Request #815: [FEATURE] Add support for f:form.* viewhelper

0 of 600 new or added lines in 15 files covered. (0.0%)

1105 of 2111 relevant lines covered (52.34%)

5.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Classes/XClass/ViewHelpers/Form/RadioViewHelper.php
1
<?php
2

3
/*
4
 * This file is part of the "headless" Extension for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.md file that was distributed with this source code.
8
 */
9

10
declare(strict_types=1);
11

12
/*
13
 * This file is part of the TYPO3 CMS project.
14
 *
15
 * It is free software; you can redistribute it and/or modify it under
16
 * the terms of the GNU General Public License, either version 2
17
 * of the License, or any later version.
18
 *
19
 * For the full copyright and license information, please read the
20
 * LICENSE.txt file that was distributed with this source code.
21
 *
22
 * The TYPO3 project - inspiring people to share!
23
 */
24

25
namespace FriendsOfTYPO3\Headless\XClass\ViewHelpers\Form;
26

27
/**
28
 * ViewHelper which creates a simple radio button :html:`<input type="radio">`.
29
 *
30
 * Examples
31
 * ========
32
 *
33
 * Simple
34
 * ------
35
 *
36
 * ::
37
 *
38
 *    <f:form.radio name="myRadioButton" value="someValue" />
39
 *
40
 * Output::
41
 *
42
 *    {
43
 *      "type": "radio",
44
 *      "name": "tx_extension_plugin[myRadioButton]",
45
 *      "value": "someValue"
46
 *    }
47
 *
48
 * Preselect
49
 * ---------
50
 *
51
 * ::
52
 *
53
 *    <f:form.radio name="myRadioButton" value="someValue" checked="{object.value} == 5" />
54
 *
55
 * Output::
56
 *
57
 *    {
58
 *       "type": "radio",
59
 *       "name": "tx_extension_plugin[myRadioButton]",
60
 *       "value": "someValue"
61
 *       "checked: "checked"
62
 *    }
63
 *
64
 * Depending on bound ``object`` to surrounding :ref:`f:form <typo3-fluid-form>`.
65
 *
66
 * Bind to object property
67
 * -----------------------
68
 *
69
 * ::
70
 *
71
 *    <f:form.radio property="newsletter" value="1" /> yes
72
 *    <f:form.radio property="newsletter" value="0" /> no
73
 *
74
 * Output::
75
 *
76
 *    {
77
 *      "type": "radio",
78
 *      "name": "tx_extension_plugin[user][newsletter]",
79
 *      "value": 1,
80
 *      "checked": "checked"
81
 *    },
82
 *    {
83
 *      "type": "radio",
84
 *      "name": "tx_extension_plugin[user][newsletter]",
85
 *      "value": 0
86
 *    }
87
 *
88
 * Depending on property ``newsletter``.
89
 */
90
final class RadioViewHelper extends AbstractFormFieldViewHelper
91
{
92
    public function initializeArguments(): void
93
    {
NEW
94
        parent::initializeArguments();
×
NEW
95
        $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this ViewHelper', false, 'f3-form-error');
×
NEW
96
        $this->registerArgument('checked', 'bool', 'Specifies that the input element should be preselected');
×
NEW
97
        $this->registerArgument('value', 'string', 'Value of input tag. Required for radio buttons', true);
×
98
    }
99

100
    public function render(): string
101
    {
NEW
102
        $this->data = json_decode(parent::render(), true);
×
103

NEW
104
        $checked = $this->arguments['checked'];
×
105

NEW
106
        $this->data['type'] = 'radio';
×
107

NEW
108
        $nameAttribute = $this->getName();
×
NEW
109
        $valueAttribute = $this->getValueAttribute();
×
110

NEW
111
        $propertyValue = null;
×
NEW
112
        if ($this->hasMappingErrorOccurred()) {
×
NEW
113
            $propertyValue = $this->getLastSubmittedFormData();
×
114
        }
NEW
115
        if ($checked === null && $propertyValue === null) {
×
NEW
116
            $propertyValue = $this->getPropertyValue();
×
NEW
117
            $propertyValue = $this->convertToPlainValue($propertyValue);
×
118
        }
119

NEW
120
        if ($propertyValue !== null) {
×
121
            // no type-safe comparison by intention
NEW
122
            $checked = $propertyValue == $valueAttribute;
×
123
        }
124

NEW
125
        $this->registerFieldNameForFormTokenGeneration($nameAttribute);
×
NEW
126
        $this->data['name'] = $nameAttribute;
×
NEW
127
        $this->data['value'] = $valueAttribute;
×
NEW
128
        if ($checked === true) {
×
NEW
129
            $this->data['checked'] = 'checked';
×
130
        }
131

NEW
132
        $this->setErrorClassAttribute();
×
133

NEW
134
        return json_encode($this->data);
×
135
    }
136
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc