• 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/AbstractFormFieldViewHelper.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
use TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper as CoreAbstractFormFieldViewHelper;
28
use TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper;
29

30
/**
31
 * Abstract Form ViewHelper. Bundles functionality related to direct property access of objects in other Form ViewHelpers.
32
 *
33
 * If you set the "property" attribute to the name of the property to resolve from the object, this class will
34
 * automatically set the name and value of a form element.
35
 *
36
 * Note this set of ViewHelpers is tailored to be used only in extbase context.
37
 */
38
abstract class AbstractFormFieldViewHelper extends CoreAbstractFormFieldViewHelper
39
{
40
    protected array $data = [];
41

42
    public function render(): string
43
    {
NEW
44
        parent::render();
×
45

NEW
46
        $attributes = [];
×
NEW
47
        foreach ($this->tag->getAttributes() as $key => $value) {
×
NEW
48
            if (str_starts_with($key, 'data-')) {
×
NEW
49
                $key = substr($key, strpos('data-', $key) + 5);
×
NEW
50
                $attributes['data'][$key] = $value;
×
NEW
51
                continue;
×
52
            }
53

NEW
54
            $attributes[$key] = $value;
×
55
        }
NEW
56
        return json_encode($attributes);
×
57
    }
58

59
    /**
60
     * Renders a hidden field with the same name as the element, to make sure the empty value is submitted
61
     * in case nothing is selected. This is needed for checkbox and multiple select fields
62
     */
63
    protected function renderHiddenFieldForEmptyValue(): string
64
    {
NEW
65
        $hiddenFieldNames = [];
×
NEW
66
        $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
×
NEW
67
        if ($viewHelperVariableContainer->exists(
×
NEW
68
            FormViewHelper::class,
×
NEW
69
            'renderedHiddenFields'
×
NEW
70
        )
×
71
        ) {
NEW
72
            $hiddenFieldNames = $viewHelperVariableContainer->get(
×
NEW
73
                FormViewHelper::class,
×
NEW
74
                'renderedHiddenFields'
×
NEW
75
            );
×
76
        }
NEW
77
        $fieldName = $this->getName();
×
NEW
78
        if (substr($fieldName, -2) === '[]') {
×
NEW
79
            $fieldName = substr($fieldName, 0, -2);
×
80
        }
NEW
81
        if (!in_array($fieldName, $hiddenFieldNames, true)) {
×
NEW
82
            $hiddenFieldNames[] = $fieldName;
×
NEW
83
            $viewHelperVariableContainer->addOrUpdate(
×
NEW
84
                FormViewHelper::class,
×
NEW
85
                'renderedHiddenFields',
×
NEW
86
                $hiddenFieldNames
×
NEW
87
            );
×
NEW
88
            return json_encode($this->addHiddenField(htmlspecialchars($fieldName), ''));
×
89
        }
NEW
90
        return '';
×
91
    }
92

93
    protected function addHiddenField(string $name, mixed $value): array
94
    {
NEW
95
        $tmp = [];
×
NEW
96
        $tmp['name'] = $name;
×
NEW
97
        $tmp['type'] = 'hidden';
×
NEW
98
        $tmp['value'] = $value;
×
99

NEW
100
        return $tmp;
×
101
    }
102
}
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