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

CPS-IT / handlebars-forms / 22340918685

24 Feb 2026 07:26AM UTC coverage: 0.0%. Remained the same
22340918685

push

github

eliashaeussler
[TASK] Add ViewHelper arguments to CountrySelect and Select processors

0 of 20 new or added lines in 2 files covered. (0.0%)

45 existing lines in 2 files now uncovered.

0 of 484 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/Classes/DataProcessing/ProcessFormProcessor.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars_forms".
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17

18
namespace CPSIT\Typo3HandlebarsForms\DataProcessing;
19

20
use Psr\Http\Message;
21
use Psr\Log;
22
use Symfony\Component\DependencyInjection;
23
use TYPO3\CMS\Fluid;
24
use TYPO3\CMS\Form;
25
use TYPO3\CMS\Frontend;
26
use TYPO3Fluid\Fluid as FluidStandalone;
27

28
/**
29
 * ProcessFormProcessor
30
 *
31
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
32
 * @license GPL-2.0-or-later
33
 */
34
#[DependencyInjection\Attribute\AutoconfigureTag('data.processor', ['identifier' => 'process-form'])]
35
final readonly class ProcessFormProcessor implements Frontend\ContentObject\DataProcessorInterface
36
{
37
    private const CONTENT_PLACEHOLDER = '###FORM_CONTENT###';
38

39
    /**
40
     * @param DependencyInjection\ServiceLocator<Value\ValueProcessor> $valueProcessors
41
     */
42
    public function __construct(
×
43
        private Log\LoggerInterface $logger,
44
        private Fluid\Core\Rendering\RenderingContextFactory $renderingContextFactory,
45
        private Renderable\FormRenderableProcessor $formRenderableProcessor,
46
        #[DependencyInjection\Attribute\AutowireLocator('handlebars_forms.value_processor', defaultIndexMethod: 'getName')]
47
        private DependencyInjection\ServiceLocator $valueProcessors,
48
    ) {}
×
49

50
    /**
51
     * @param array<string, mixed> $contentObjectConfiguration
52
     * @param array<string, mixed> $processorConfiguration
53
     * @param array<string, mixed> $processedData
54
     * @return array<string, mixed>
55
     */
56
    public function process(
×
57
        Frontend\ContentObject\ContentObjectRenderer $cObj,
58
        array $contentObjectConfiguration,
59
        array $processorConfiguration,
60
        array $processedData,
61
    ): array {
62
        $formRuntime = $contentObjectConfiguration['variables.']['form'] ?? null;
×
63

64
        if (!($formRuntime instanceof Form\Domain\Runtime\FormRuntime)) {
×
65
            $this->logger->error(
×
66
                'Form runtime is not available when trying to process form with plugin uid "{uid}".',
×
67
                ['uid' => $cObj->data['uid'] ?? '(unknown)'],
×
68
            );
×
69

70
            return $processedData;
×
71
        }
72

73
        // Create and prepare Fluid rendering context
74
        $renderingContext = $this->renderingContextFactory->create();
×
75
        $renderingContext->setAttribute(Message\ServerRequestInterface::class, $formRuntime->getRequest());
×
76
        $renderingContext->getViewHelperVariableContainer()->addOrUpdate(
×
77
            Form\ViewHelpers\RenderRenderableViewHelper::class,
×
78
            'formRuntime',
×
79
            $formRuntime,
×
80
        );
×
81

82
        // Render form and process renderables as part of the form's renderChildrenClosure.
83
        // Since the final rendered form content (which especially contains all relevant hidden fields)
84
        // is not yet available when processing renderables, we temporarily pass a content placeholder
85
        // for all configured CONTENT values and replace them with the real content value later.
86
        $this->formRenderableProcessor->process(
×
87
            $formRuntime,
×
88
            $renderingContext,
×
89
            function (FluidStandalone\Core\ViewHelper\TagBuilder $tagBuilder) use (
×
90
                $cObj,
×
91
                $formRuntime,
×
92
                &$processedData,
×
93
                $processorConfiguration,
×
94
                $renderingContext,
×
UNCOV
95
                &$tag,
×
96
            ) {
×
97
                $tag = $tagBuilder;
×
UNCOV
98
                $tag->setContent(self::CONTENT_PLACEHOLDER);
×
99

100
                $viewModel = new Renderable\RenderableViewModel($renderingContext, null, $tag);
×
101
                $processedData = $this->processRenderable($formRuntime, $processorConfiguration, $cObj, $viewModel) ?? [];
×
102

103
                return '';
×
UNCOV
104
            },
×
105
        );
×
106

107
        $formContent = $tag?->getContent();
×
108

109
        // Replace content placeholder with final rendered form content
UNCOV
110
        if ($formContent !== null) {
×
111
            array_walk_recursive($processedData, static function (&$value) use ($formContent) {
×
UNCOV
112
                if (is_string($value)) {
×
UNCOV
113
                    $value = str_replace(self::CONTENT_PLACEHOLDER, $formContent, $value);
×
114
                }
UNCOV
115
            });
×
116
        }
117

118
        return $processedData;
×
119
    }
120

121
    /**
122
     * @param array<string, mixed> $configuration
123
     * @return array<string, mixed>|null
124
     */
UNCOV
125
    private function processRenderable(
×
126
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
127
        array $configuration,
128
        Frontend\ContentObject\ContentObjectRenderer $cObj,
129
        Renderable\RenderableViewModel $viewModel,
130
    ): ?array {
131
        $processedData = [];
×
132

133
        // Early return on configured "if" condition evaluating to false
UNCOV
134
        if (!$this->checkIf($configuration, $renderable, $cObj, $viewModel)) {
×
135
            return null;
×
136
        }
137

138
        foreach ($configuration as $key => $value) {
×
139
            $keyWithoutDot = rtrim($key, '.');
×
UNCOV
140
            $keyWithDot = $keyWithoutDot . '.';
×
141

UNCOV
142
            if (is_array($value) && !array_key_exists($keyWithoutDot, $processedData)) {
×
143
                $processedValue = $this->processRenderable($renderable, $value, $cObj, $viewModel);
×
144

UNCOV
145
                if (is_array($processedValue)) {
×
UNCOV
146
                    $processedData[$keyWithoutDot] = $processedValue;
×
147
                }
148
            }
149

150
            if (!is_string($value)) {
×
151
                continue;
×
152
            }
153

154
            $valueConfiguration = $configuration[$keyWithDot] ?? [];
×
155

156
            // Process configured value
157
            if ($this->valueProcessors->has($value)) {
×
158
                $processedValue = $this->valueProcessors->get($value)->process(
×
159
                    $renderable,
×
160
                    $viewModel,
×
161
                    new Value\ProcessingContext(
×
162
                        $valueConfiguration,
×
163
                        fn(
×
164
                            array $contextConfiguration,
×
165
                            ?Form\Domain\Model\Renderable\RootRenderableInterface $contextRenderable = null,
×
166
                            ?Renderable\RenderableViewModel $contextViewModel = null,
×
167
                        ) => $this->processRenderable(
×
UNCOV
168
                            $contextRenderable ?? $renderable,
×
169
                            $contextConfiguration,
×
UNCOV
170
                            $cObj,
×
UNCOV
171
                            $contextViewModel ?? $viewModel,
×
UNCOV
172
                        ),
×
173
                    ),
×
174
                );
×
175
            } else {
UNCOV
176
                $processedValue = $value;
×
177
            }
178

179
            // Skip further processing if processed value is not a string (all COR related methods require a string value)
180
            if (!is_string($processedValue)) {
×
UNCOV
181
                $processedData[$keyWithoutDot] = $processedValue;
×
UNCOV
182
                continue;
×
183
            }
184

185
            // Process value with stdWrap
UNCOV
186
            if (is_array($valueConfiguration['stdWrap.'] ?? null)) {
×
187
                $processedValue = $cObj->stdWrap($processedValue, $valueConfiguration['stdWrap.']);
×
188
            }
189

190
            // Skip value if a configured "if" evaluates to false
UNCOV
191
            if (is_array($valueConfiguration['if.'] ?? null)) {
×
192
                $valueConfiguration['if.']['value'] ??= $processedValue;
×
193

UNCOV
194
                if (!$cObj->checkIf($valueConfiguration['if.'])) {
×
195
                    continue;
×
196
                }
197
            }
198

UNCOV
199
            $processedData[$keyWithoutDot] = $processedValue;
×
200
        }
201

UNCOV
202
        return $processedData;
×
203
    }
204

205
    /**
206
     * @param array<string, mixed> $configuration
207
     */
208
    private function checkIf(
×
209
        array &$configuration,
210
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
211
        Frontend\ContentObject\ContentObjectRenderer $cObj,
212
        Renderable\RenderableViewModel $viewModel,
213
    ): bool {
214
        if (!is_array($configuration['if.'] ?? null)) {
×
215
            return true;
×
216
        }
217

218
        $cObjTemp = clone $cObj;
×
219

220
        if (is_string($configuration['if.']['value'] ?? null) && is_array($configuration['if.']['value.'] ?? null)) {
×
221
            $processedValue = $this->processRenderable(
×
222
                $renderable,
×
UNCOV
223
                [
×
224
                    'value' => $configuration['if.']['value'],
×
UNCOV
225
                    'value.' => $configuration['if.']['value.'],
×
226
                ],
×
UNCOV
227
                $cObj,
×
UNCOV
228
                $viewModel,
×
229
            );
×
230

UNCOV
231
            $cObjTemp->setCurrentVal($processedValue['value'] ?? null);
×
232

233
            unset($configuration['if.']['value'], $configuration['if.']['value.']);
×
234
        }
235

UNCOV
236
        if (!$cObjTemp->checkIf($configuration['if.'])) {
×
UNCOV
237
            return false;
×
238
        }
239

UNCOV
240
        unset($configuration['if.']);
×
241

UNCOV
242
        return true;
×
243
    }
244
}
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