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

TYPO3-Headless / headless / 10851234187

13 Sep 2024 02:45PM UTC coverage: 67.643% (+0.02%) from 67.625%
10851234187

push

github

web-flow
[TASK] Expose submitButtonLabel from editor in json form response (#773)

Resolves: #767

5 of 6 new or added lines in 1 file covered. (83.33%)

1108 of 1638 relevant lines covered (67.64%)

2.75 hits per line

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

95.56
/Classes/Form/Decorator/AbstractFormDefinitionDecorator.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
namespace FriendsOfTYPO3\Headless\Form\Decorator;
13

14
use function in_array;
15

16
abstract class AbstractFormDefinitionDecorator implements DefinitionDecoratorInterface
17
{
18
    /**
19
     * @var array<string, mixed>
20
     */
21
    protected array $formStatus;
22
    protected string $formId = '';
23

24
    public function __construct(array $formStatus = [])
25
    {
26
        $this->formStatus = $formStatus;
3✔
27
    }
28

29
    /**
30
     * @param array<string, mixed> $definition
31
     * @return array<string,array<mixed>>
32
     */
33
    public function __invoke(array $definition, int $currentPage): array
34
    {
35
        $decorated = [];
2✔
36

37
        $this->formId = $definition['identifier'];
2✔
38
        $pageElements = $definition['renderables'][$currentPage]['renderables'] ?? [];
2✔
39
        $submitLabel = $definition['renderingOptions']['submitButtonLabel'] ?? '';
2✔
40
        $submitLabelFromEditor = [];
2✔
41

42
        if ($submitLabel !== '') {
2✔
NEW
43
            $submitLabelFromEditor = ['submitButtonLabel' => $submitLabel];
×
44
        }
45

46
        $decorated['id'] = $this->formId;
2✔
47
        $decorated['api'] = $this->formStatus;
2✔
48
        $decorated['i18n'] = [...$submitLabelFromEditor, ...($definition['i18n']['properties'] ?? [])];
2✔
49
        $decorated['elements'] = $this->handleRenderables($pageElements);
2✔
50

51
        return $this->overrideDefinition($decorated, $definition, $currentPage);
2✔
52
    }
53

54
    /**
55
     * @param array<string, mixed> $renderables
56
     * @return array<string, mixed>
57
     */
58
    protected function handleRenderables(array $renderables): array
59
    {
60
        foreach ($renderables as &$element) {
2✔
61
            if (in_array($element['type'], ['Fieldset', 'GridRow'], true) &&
1✔
62
                is_array($element['renderables'] ?? []) &&
1✔
63
                ($element['renderables'] ?? []) !== []) {
1✔
64
                $element['elements'] = $this->handleRenderables($element['renderables']);
1✔
65
                unset($element['renderables']);
1✔
66
            } else {
67
                $element = $this->prepareElement($element);
1✔
68
            }
69
        }
70

71
        return $renderables;
2✔
72
    }
73

74
    /**
75
     * @param array<string, mixed> $element
76
     * @return array<string, mixed>
77
     */
78
    protected function prepareElement(array $element): array
79
    {
80
        $element['name'] = 'tx_form_formframework[' . $this->formId . '][' . $element['identifier'] . ']';
1✔
81

82
        $element = $this->overrideElement($element);
1✔
83

84
        if (isset($element['renderingOptions']['FEOverrideType'])) {
1✔
85
            $element['type'] = $element['renderingOptions']['FEOverrideType'];
1✔
86
            unset($element['renderingOptions']['FEOverrideType']);
1✔
87
        }
88

89
        if (in_array($element['type'], ['ImageUpload', 'FileUpload'])) {
1✔
90
            unset($element['properties']['saveToFileMount']);
1✔
91
        }
92

93
        if (!isset($element['validators'])) {
1✔
94
            return $element;
1✔
95
        }
96

97
        $validators = [];
1✔
98

99
        foreach ($element['validators'] as $validator) {
1✔
100
            if ($validator['identifier'] === 'RegularExpression') {
1✔
101
                $jsRegex = $validator['FERegularExpression'] ?? null;
1✔
102

103
                if ($jsRegex) {
1✔
104
                    $validator['options']['regularExpression'] = $jsRegex;
1✔
105
                    unset($validator['FERegularExpression']);
1✔
106
                }
107
            }
108

109
            if ((int)($validator['backendOnly'] ?? 0)) {
1✔
110
                unset($validator);
×
111
            }
112

113
            if (isset($validator)) {
1✔
114
                $validators[] = $validator;
1✔
115
            }
116
        }
117

118
        $element['validators'] = $validators;
1✔
119

120
        return $element;
1✔
121
    }
122

123
    /**
124
     * @param array<string, mixed> $element
125
     * @return array<string, mixed>
126
     */
127
    protected function overrideElement(array $element): array
128
    {
129
        return $element;
1✔
130
    }
131

132
    /**
133
     * @param array<string, mixed> $decorated
134
     * @param array<string, mixed> $definition
135
     * @param int $currentPage
136
     * @return array<string, mixed>
137
     */
138
    protected function overrideDefinition(array $decorated, array $definition, int $currentPage): array
139
    {
140
        return $decorated;
2✔
141
    }
142
}
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

© 2025 Coveralls, Inc