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

CPS-IT / handlebars-forms / 25717226720

12 May 2026 06:20AM UTC coverage: 0.538% (-0.008%) from 0.546%
25717226720

push

github

web-flow
Merge pull request #37 from CPS-IT/feature/typo3-v14

[FEATURE] Add support for TYPO3 v14.3 LTS

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

1 existing line in 1 file now uncovered.

7 of 1301 relevant lines covered (0.54%)

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\Core;
23
use TYPO3\CMS\Fluid;
24
use TYPO3\CMS\Form;
25

26
/**
27
 * RenderablesContentObject
28
 *
29
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
30
 * @license GPL-2.0-or-later
31
 */
32
#[DependencyInjection\Attribute\AutoconfigureTag('frontend.contentobject', ['identifier' => 'HBS_RENDERABLES'])]
33
final class RenderablesContentObject extends AbstractHandlebarsFormsContentObject
34
{
35
    use CanUpdateRegister;
36

37
    private const IDENTIFIER_COUNT = 'HBS_RENDERABLES_COUNT';
38
    private const IDENTIFIER_CURRENT = 'HBS_RENDERABLES_CURRENT';
39

40
    /**
41
     * @param iterable<Domain\ViewModel\Builder\ViewModelBuilder<Form\Domain\Model\Renderable\RootRenderableInterface>> $viewModelBuilders
42
     */
43
    public function __construct(
×
44
        #[DependencyInjection\Attribute\AutowireIterator('handlebars_forms.view_model_builder')]
45
        private readonly iterable $viewModelBuilders,
46
        private readonly Context\ContextStack $contextStack,
47
        private readonly Context\ValueCollector $valueCollector,
48
    ) {
NEW
49
        $this->typo3Version = new Core\Information\Typo3Version();
×
50
    }
51

52
    /**
53
     * @return list<mixed>
54
     */
55
    protected function resolve(array $configuration, Context\ValueResolutionContext $context): array
×
56
    {
57
        $baseRenderable = $renderable = $context->renderable;
×
58
        $processedRenderables = [];
×
59

60
        // Use current page as base renderable if we're on root form context
61
        if ($baseRenderable instanceof Form\Domain\Runtime\FormRuntime) {
×
62
            $renderable = $baseRenderable->getCurrentPage() ?? $baseRenderable;
×
63
        }
64

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

106
        // Add renderables count to TSFE register
NEW
107
        $this->updateRegister(self::IDENTIFIER_COUNT, count($renderables));
×
108

109
        foreach ($renderables as $index => $child) {
×
110
            if (!$this->isEnabled($child)) {
×
111
                continue;
×
112
            }
113

114
            // Add current renderable index to TSFE register
NEW
115
            $this->updateRegister(self::IDENTIFIER_CURRENT, $index);
×
116

117
            try {
118
                if (array_key_exists($child->getType() . '.', $configuration)) {
×
119
                    // Use configured type-specific configuration (e.g. "Fieldset." for fieldsets)
120
                    $childConfiguration = $configuration[$child->getType() . '.'];
×
121
                } elseif (is_string($configuration[$child->getType()] ?? null)) {
×
122
                    // Render single content object without further configuration (e.g. HBS_PASSTHROUGH)
123
                    $processedRenderables[] = $this->renderRenderable(
×
124
                        $context,
×
125
                        $child,
×
126
                        $configuration[$child->getType()],
×
127
                    );
×
128

129
                    continue;
×
130
                } elseif (!array_key_exists('default.', $configuration)) {
×
131
                    // Skip rendering on missing fallback config
132
                    continue;
×
133
                } else {
134
                    // Use configured fallback configuration ("default.")
135
                    $childConfiguration = $configuration['default.'];
×
136
                }
137

138
                if (is_array($childConfiguration)) {
×
139
                    $childViewModel = $this->buildViewModel($child, $context->renderingContext);
×
140
                } else {
141
                    $childConfiguration = [];
×
142
                    $childViewModel = new Domain\ViewModel\SimpleViewModel($child);
×
143
                }
144

145
                $processedChild = $context->process($childConfiguration, $child, $childViewModel);
×
146

147
                if ($processedChild !== null) {
×
148
                    $processedRenderables[] = $processedChild;
×
149
                }
150
            } finally {
NEW
151
                $this->updateRegister(self::IDENTIFIER_CURRENT);
×
152
            }
153
        }
154

NEW
155
        $this->updateRegister(self::IDENTIFIER_COUNT);
×
156

157
        return $processedRenderables;
×
158
    }
159

160
    private function renderRenderable(
×
161
        Context\ValueResolutionContext $context,
162
        Form\Domain\Model\Renderable\RenderableInterface $renderable,
163
        string $contentObject,
164
    ): mixed {
165
        $this->contextStack->push($context->withRenderable($renderable));
×
166

167
        try {
168
            $result = $this->cObj?->cObjGetSingle($contentObject, []);
×
169
        } finally {
170
            $this->contextStack->pop();
×
171
        }
172

173
        if (is_string($result) && $this->valueCollector->has($result)) {
×
174
            return $this->valueCollector->load($result);
×
175
        }
176

177
        return $result;
×
178
    }
179

180
    private function buildViewModel(
×
181
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
182
        Fluid\Core\Rendering\RenderingContext $renderingContext,
183
    ): Domain\ViewModel\ViewModel {
184
        foreach ($this->viewModelBuilders as $viewModelBuilder) {
×
185
            if ($viewModelBuilder->supports($renderable)) {
×
186
                return $viewModelBuilder->build($renderable, $renderingContext);
×
187
            }
188
        }
189

190
        return new Domain\ViewModel\SimpleViewModel($renderable);
×
191
    }
192

193
    private function isElement(Form\Domain\Model\Renderable\RenderableInterface $renderable): bool
×
194
    {
195
        return $renderable instanceof Form\Domain\Model\FormElements\FormElementInterface
×
196
            && $this->isEnabled($renderable)
×
197
        ;
×
198
    }
199

200
    private function isEnabled(Form\Domain\Model\Renderable\RenderableInterface $renderable): bool
×
201
    {
202
        if (!$renderable->isEnabled()) {
×
203
            return false;
×
204
        }
205

206
        while (($renderable = $renderable->getParentRenderable()) !== null) {
×
207
            if (!$renderable->isEnabled()) {
×
208
                return false;
×
209
            }
210
        }
211

212
        return true;
×
213
    }
214
}
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