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

CPS-IT / handlebars-forms / 23834583270

01 Apr 2026 06:07AM UTC coverage: 0.593% (-0.06%) from 0.654%
23834583270

Pull #19

github

web-flow
Merge 9f407ed77 into bd42335b8
Pull Request #19: [FEATURE] Support proper rendering of `SummaryPage` renderables

0 of 115 new or added lines in 4 files covered. (0.0%)

1 existing line in 1 file now uncovered.

7 of 1181 relevant lines covered (0.59%)

0.02 hits per line

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

0.0
/Classes/ContentObject/FormValueContentObject.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\ContentObject;
19

20
use CPSIT\Typo3HandlebarsForms\Domain;
21
use CPSIT\Typo3HandlebarsForms\Fluid;
22
use Symfony\Component\DependencyInjection;
23
use TYPO3\CMS\Form;
24

25
/**
26
 * FormValueContentObject
27
 *
28
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
29
 * @license GPL-2.0-or-later
30
 */
31
#[DependencyInjection\Attribute\AutoconfigureTag('frontend.contentobject', ['identifier' => 'HBS_FORM_VALUE'])]
32
final class FormValueContentObject extends AbstractHandlebarsFormsContentObject
33
{
NEW
34
    public function __construct(
×
35
        private readonly Fluid\ViewHelperInvoker $viewHelperInvoker,
NEW
36
    ) {}
×
37

NEW
38
    protected function resolve(array $configuration, Context\ValueResolutionContext $context): mixed
×
39
    {
NEW
40
        $outputInstruction = $configuration['output'] ?? null;
×
NEW
41
        $outputConfiguration = $configuration['output.'] ?? null;
×
NEW
42
        $formValueViewModel = null;
×
NEW
43
        $formValueVariableName = 'formValue';
×
44

NEW
45
        $this->viewHelperInvoker->invoke(
×
NEW
46
            $context->renderingContext,
×
NEW
47
            Form\ViewHelpers\RenderFormValueViewHelper::class,
×
NEW
48
            [
×
NEW
49
                'renderable' => $context->renderable,
×
NEW
50
                'as' => $formValueVariableName,
×
NEW
51
            ],
×
NEW
52
            function () use ($context, &$formValueViewModel, $formValueVariableName) {
×
NEW
53
                $formValueContext = $context->renderingContext->getVariableProvider()->get($formValueVariableName);
×
54

NEW
55
                if (!is_array($formValueContext)) {
×
NEW
56
                    return null;
×
57
                }
58

59
                /** @var array<string, mixed> $formValueContext */
NEW
60
                $formValueViewModel = Domain\ViewModel\FormValueViewModel::fromArray($formValueContext);
×
61

NEW
62
                return '';
×
NEW
63
            },
×
NEW
64
        );
×
65

66
        // Early return if form value could not be resolved
NEW
67
        if ($formValueViewModel === null) {
×
NEW
68
            return null;
×
69
        }
70

71
        // Normalize output configuration
NEW
72
        if (!is_array($outputConfiguration)) {
×
NEW
73
            $outputConfiguration = null;
×
74
        }
75

76
        // Apply view model to context
NEW
77
        $context = $context->withViewModel($formValueViewModel);
×
78

NEW
79
        if (is_string($outputInstruction)) {
×
NEW
80
            return $this->processRenderingInstruction($context, $outputInstruction, $outputConfiguration ?? []);
×
81
        }
82

83
        // Resolve complex rendering configuration
NEW
84
        if (is_array($outputConfiguration)) {
×
NEW
85
            return $this->processRenderingConfiguration($context, $outputConfiguration);
×
86
        }
87

88
        // Return processed value in case no rendering instructions are specified
NEW
89
        return $formValueViewModel->processedValue;
×
90
    }
91

92
    /**
93
     * @param array<string|int, mixed> $configuration
94
     * @return array<string|int, mixed>
95
     */
NEW
96
    private function processRenderingConfiguration(
×
97
        Context\ValueResolutionContext $context,
98
        array $configuration,
99
    ): array {
NEW
100
        $processedData = [];
×
101

NEW
102
        foreach ($configuration as $key => $value) {
×
NEW
103
            $keyWithoutDot = rtrim((string)$key, '.');
×
NEW
104
            $keyWithDot = $keyWithoutDot . '.';
×
105

NEW
106
            if (is_array($value)) {
×
NEW
107
                if (!array_key_exists($keyWithoutDot, $processedData)) {
×
108
                    // Process nested rendering configuration
NEW
109
                    $processedData[$keyWithoutDot] = $this->processRenderingConfiguration($context, $value);
×
110
                }
NEW
111
            } elseif (is_string($value)) {
×
NEW
112
                $valueConfiguration = $configuration[$keyWithDot] ?? [];
×
113

NEW
114
                if (!is_array($valueConfiguration)) {
×
NEW
115
                    $valueConfiguration = [];
×
116
                }
117

NEW
118
                $processedData[$keyWithoutDot] = $this->processRenderingInstruction(
×
NEW
119
                    $context,
×
NEW
120
                    $value,
×
NEW
121
                    $valueConfiguration,
×
NEW
122
                );
×
123
            }
124
        }
125

NEW
126
        return $processedData;
×
127
    }
128

129
    /**
130
     * @param array<string|int, mixed> $configuration
131
     */
NEW
132
    private function processRenderingInstruction(
×
133
        Context\ValueResolutionContext $context,
134
        string $value,
135
        array $configuration,
136
    ): mixed {
137
        /** @var Domain\ViewModel\FormValueViewModel $viewModel */
NEW
138
        $viewModel = $context->viewModel;
×
139

NEW
140
        return match ($value) {
×
NEW
141
            'EACH_PROCESSED_VALUE', 'EACH_VALUE' => $this->processEachValue($context, $configuration),
×
NEW
142
            'IS_MULTI_VALUE' => $viewModel->isMultiValue,
×
NEW
143
            'IS_SECTION' => $viewModel->isSection,
×
NEW
144
            'PROCESSED_VALUE' => $viewModel->processedValue,
×
NEW
145
            'VALUE' => $viewModel->value,
×
NEW
146
            default => $value,
×
NEW
147
        };
×
148
    }
149

150
    /**
151
     * @param array<string|int, mixed> $configuration
152
     * @return list<array<string|int, mixed>>
153
     */
NEW
154
    private function processEachValue(Context\ValueResolutionContext $context, array $configuration): array
×
155
    {
156
        /** @var Domain\ViewModel\FormValueViewModel $viewModel */
NEW
157
        $viewModel = $context->viewModel;
×
NEW
158
        $processedData = [];
×
159

NEW
160
        foreach ($viewModel->getChildren() as $child) {
×
NEW
161
            $processedData[] = $this->processRenderingConfiguration($context->withViewModel($child), $configuration);
×
162
        }
163

NEW
164
        return $processedData;
×
165
    }
166
}
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