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

CPS-IT / handlebars-forms / 23844280405

01 Apr 2026 10:32AM UTC coverage: 0.591% (-0.001%) from 0.592%
23844280405

push

github

web-flow
Merge pull request #22 from CPS-IT/task/default

0 of 4 new or added lines in 1 file covered. (0.0%)

3 existing lines in 1 file now uncovered.

7 of 1185 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/RenderablesContentObject.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 Symfony\Component\DependencyInjection;
22
use TYPO3\CMS\Fluid;
23
use TYPO3\CMS\Form;
24

25
/**
26
 * RenderablesContentObject
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_RENDERABLES'])]
32
final class RenderablesContentObject extends AbstractHandlebarsFormsContentObject
33
{
34
    private const IDENTIFIER_COUNT = 'HBS_RENDERABLES_COUNT';
35
    private const IDENTIFIER_CURRENT = 'HBS_RENDERABLES_CURRENT';
36

37
    /**
38
     * @param iterable<Domain\ViewModel\Builder\ViewModelBuilder<Form\Domain\Model\Renderable\RootRenderableInterface>> $viewModelBuilders
39
     */
40
    public function __construct(
×
41
        #[DependencyInjection\Attribute\AutowireIterator('handlebars_forms.view_model_builder')]
42
        private readonly iterable $viewModelBuilders,
43
        private readonly PassthroughContentObject $passthroughContentObject,
44
    ) {}
×
45

46
    /**
47
     * @return list<mixed>
48
     */
49
    protected function resolve(array $configuration, Context\ValueResolutionContext $context): array
×
50
    {
51
        $baseRenderable = $renderable = $context->renderable;
×
52
        $processedRenderables = [];
×
53

54
        // Use current page as base renderable if we're on root form context
55
        if ($baseRenderable instanceof Form\Domain\Runtime\FormRuntime) {
×
56
            $renderable = $baseRenderable->getCurrentPage() ?? $baseRenderable;
×
57
        }
58

59
        // Fetch renderables from base renderable:
60
        // - On summary pages, the base renderable defines the selection of renderables:
61
        //   + If the incoming renderable is the summary page, we use ALL elements (no sections) of the configured form.
62
        //   + If the incoming renderable is the root form, we explicitly render the summary page renderable
63
        //     to allow further configuration of this specific page type. In TypoScript, the form renderables may
64
        //     still be rendered for summary pages by using a combination of HBS_RENDERABLES objects for form & page:
65
        //       formData {
66
        //         items = HBS_RENDERABLES
67
        //         items {
68
        //           # ...
69
        //           SummaryPage {
70
        //             elements = HBS_RENDERABLES
71
        //             elements {
72
        //               Text { ... }
73
        //               # ...
74
        //             }
75
        //           }
76
        //         }
77
        //       }
78
        // - On default sections (e.g. non-summary pages), this reflects all direct children.
79
        // - On all other composite renderables, this reflects all renderables recursively (including deeply nested
80
        //   renderables).
81
        // - If we have a non-composite base renderable in place, we do nothing since this value resolver only handles
82
        //   composite renderables.
83
        if ($baseRenderable instanceof Form\Domain\Model\FormElements\Page && $baseRenderable->getType() === 'SummaryPage') {
×
84
            $renderables = array_filter(
×
85
                $baseRenderable->getRootForm()->getRenderablesRecursively(),
×
86
                $this->isElement(...),
×
87
            );
×
88
        } elseif ($renderable instanceof Form\Domain\Model\FormElements\Page && $renderable->getType() === 'SummaryPage') {
×
89
            $renderables = [$renderable];
×
90
        } elseif ($renderable instanceof Form\Domain\Model\FormElements\AbstractSection) {
×
91
            $renderables = $renderable->getElements();
×
92
        } elseif ($renderable instanceof Form\Domain\Model\Renderable\CompositeRenderableInterface) {
×
93
            $renderables = $renderable->getRenderablesRecursively();
×
94
        } else {
95
            $renderables = [];
×
96
        }
97

98
        // Add renderables count to TSFE register
99
        // @todo Use $this->request->getAttribute('frontend.register.stack') in TYPO3 v14
100
        $tsfe = $this->getTypoScriptFrontendController();
×
101
        $tsfe->register[self::IDENTIFIER_COUNT] = count($renderables);
×
102

103
        foreach ($renderables as $index => $child) {
×
104
            if (!$this->isEnabled($child)) {
×
105
                continue;
×
106
            }
107

NEW
108
            if (array_key_exists($child->getType() . '.', $configuration)) {
×
109
                // Use configured type-specific configuration (e.g. "Fieldset." for fieldsets)
NEW
110
                $childConfiguration = $configuration[$child->getType() . '.'];
×
NEW
111
            } elseif (!array_key_exists('default.', $configuration)) {
×
112
                // Pass through rendering to original Fluid partial on missing fallback config
UNCOV
113
                $processedRenderables[] = $this->passthroughContentObject->render();
×
UNCOV
114
                continue;
×
115
            } else {
116
                // Use configured fallback configuration ("default.")
NEW
117
                $childConfiguration = $configuration['default.'];
×
118
            }
119

120
            if (is_array($childConfiguration)) {
×
UNCOV
121
                $childViewModel = $this->buildViewModel($child, $context->renderingContext);
×
122
            } else {
123
                $childConfiguration = [];
×
124
                $childViewModel = new Domain\ViewModel\SimpleViewModel($child);
×
125
            }
126

127
            // Add current renderable index to TSFE register
128
            $tsfe->register[self::IDENTIFIER_CURRENT] = $index;
×
129

130
            try {
131
                $processedChild = $context->process($childConfiguration, $child, $childViewModel);
×
132
            } finally {
133
                unset($tsfe->register[self::IDENTIFIER_CURRENT]);
×
134
            }
135

136
            if ($processedChild !== null) {
×
137
                $processedRenderables[] = $processedChild;
×
138
            }
139
        }
140

141
        unset($tsfe->register[self::IDENTIFIER_COUNT]);
×
142

143
        return $processedRenderables;
×
144
    }
145

146
    private function buildViewModel(
×
147
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
148
        Fluid\Core\Rendering\RenderingContext $renderingContext,
149
    ): Domain\ViewModel\ViewModel {
150
        foreach ($this->viewModelBuilders as $viewModelBuilder) {
×
151
            if ($viewModelBuilder->supports($renderable)) {
×
152
                return $viewModelBuilder->build($renderable, $renderingContext);
×
153
            }
154
        }
155

156
        return new Domain\ViewModel\SimpleViewModel($renderable);
×
157
    }
158

159
    private function isElement(Form\Domain\Model\Renderable\RenderableInterface $renderable): bool
×
160
    {
161
        return $renderable instanceof Form\Domain\Model\FormElements\FormElementInterface
×
162
            && $this->isEnabled($renderable)
×
163
        ;
×
164
    }
165

166
    private function isEnabled(Form\Domain\Model\Renderable\RenderableInterface $renderable): bool
×
167
    {
168
        if (!$renderable->isEnabled()) {
×
169
            return false;
×
170
        }
171

172
        while (($renderable = $renderable->getParentRenderable()) !== null) {
×
173
            if (!$renderable->isEnabled()) {
×
174
                return false;
×
175
            }
176
        }
177

178
        return true;
×
179
    }
180
}
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