• 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/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 RENDERABLE_INDEX_IDENTIFIER = '_currentRenderableIndex';
35

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

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

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

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

97
        foreach ($renderables as $index => $child) {
×
98
            if (!$this->isEnabled($child)) {
×
99
                continue;
×
100
            }
101

102
            if (!array_key_exists($child->getType() . '.', $configuration)) {
×
103
                $processedRenderables[] = $this->passthroughContentObject->render();
×
104

105
                continue;
×
106
            }
107

108
            $childConfiguration = $configuration[$child->getType() . '.'];
×
109

110
            if (is_array($childConfiguration)) {
×
111
                $childViewModel = $this->buildViewModel($child, $context->renderingContext);
×
112
            } else {
113
                $childConfiguration = [];
×
114
                $childViewModel = new Domain\ViewModel\SimpleViewModel($child);
×
115
            }
116

117
            if ($this->cObj !== null) {
×
118
                $this->cObj->data[self::RENDERABLE_INDEX_IDENTIFIER] = $index;
×
119
            }
120

121
            try {
122
                $processedChild = $context->process($childConfiguration, $child, $childViewModel);
×
123
            } finally {
124
                if ($this->cObj !== null) {
×
125
                    unset($this->cObj->data[self::RENDERABLE_INDEX_IDENTIFIER]);
×
126
                }
127
            }
128

129
            if ($processedChild !== null) {
×
130
                $processedRenderables[] = $processedChild;
×
131
            }
132
        }
133

134
        return $processedRenderables;
×
135
    }
136

137
    private function buildViewModel(
×
138
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
139
        Fluid\Core\Rendering\RenderingContext $renderingContext,
140
    ): Domain\ViewModel\ViewModel {
141
        foreach ($this->viewModelBuilders as $viewModelBuilder) {
×
142
            if ($viewModelBuilder->supports($renderable)) {
×
143
                return $viewModelBuilder->build($renderable, $renderingContext);
×
144
            }
145
        }
146

147
        return new Domain\ViewModel\SimpleViewModel($renderable);
×
148
    }
149

NEW
150
    private function isElement(Form\Domain\Model\Renderable\RenderableInterface $renderable): bool
×
151
    {
NEW
152
        return $renderable instanceof Form\Domain\Model\FormElements\FormElementInterface
×
NEW
153
            && $this->isEnabled($renderable)
×
NEW
154
        ;
×
155
    }
156

UNCOV
157
    private function isEnabled(Form\Domain\Model\Renderable\RenderableInterface $renderable): bool
×
158
    {
159
        if (!$renderable->isEnabled()) {
×
160
            return false;
×
161
        }
162

163
        while (($renderable = $renderable->getParentRenderable()) !== null) {
×
164
            if (!$renderable->isEnabled()) {
×
165
                return false;
×
166
            }
167
        }
168

169
        return true;
×
170
    }
171
}
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