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

CPS-IT / handlebars-forms / 25364682179

05 May 2026 07:58AM UTC coverage: 0.548% (-0.008%) from 0.556%
25364682179

Pull #37

github

web-flow
Merge cb8d6f97a into de93226e1
Pull Request #37: [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 1277 relevant lines covered (0.55%)

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
    ) {
NEW
47
        $this->typo3Version = new Core\Information\Typo3Version();
×
48
    }
49

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

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

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

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

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

112
            if (array_key_exists($child->getType() . '.', $configuration)) {
×
113
                // Use configured type-specific configuration (e.g. "Fieldset." for fieldsets)
114
                $childConfiguration = $configuration[$child->getType() . '.'];
×
115
            } elseif (!array_key_exists('default.', $configuration)) {
×
116
                // Skip rendering on missing fallback config
117
                continue;
×
118
            } else {
119
                // Use configured fallback configuration ("default.")
120
                $childConfiguration = $configuration['default.'];
×
121
            }
122

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

130
            // Add current renderable index to TSFE register
NEW
131
            $this->updateRegister(self::IDENTIFIER_CURRENT, $index);
×
132

133
            try {
134
                $processedChild = $context->process($childConfiguration, $child, $childViewModel);
×
135
            } finally {
NEW
136
                $this->updateRegister(self::IDENTIFIER_CURRENT);
×
137
            }
138

139
            if ($processedChild !== null) {
×
140
                $processedRenderables[] = $processedChild;
×
141
            }
142
        }
143

NEW
144
        $this->updateRegister(self::IDENTIFIER_COUNT);
×
145

146
        return $processedRenderables;
×
147
    }
148

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

159
        return new Domain\ViewModel\SimpleViewModel($renderable);
×
160
    }
161

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

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

175
        while (($renderable = $renderable->getParentRenderable()) !== null) {
×
176
            if (!$renderable->isEnabled()) {
×
177
                return false;
×
178
            }
179
        }
180

181
        return true;
×
182
    }
183
}
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