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

CPS-IT / handlebars-forms / 23537466391

25 Mar 2026 10:55AM UTC coverage: 0.73% (-0.03%) from 0.756%
23537466391

Pull #16

github

web-flow
Merge d400b557c into 9a344a131
Pull Request #16: [FEATURE] Render original Fluid template for unconfigured renderables

0 of 34 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

7 of 959 relevant lines covered (0.73%)

0.03 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 DevTheorem\Handlebars;
22
use Symfony\Component\DependencyInjection;
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
    private const RENDERABLE_INDEX_IDENTIFIER = '_currentRenderableIndex';
36

37
    /**
38
     * @param iterable<Domain\Renderable\ViewModel\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 Domain\Renderer\FluidRenderableRenderer $fluidRenderer,
UNCOV
44
    ) {}
×
45

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

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

59
        // Fetch renderables from base renderable. On default sections (e.g. pages), this reflects
60
        // all direct children. On all other composite renderables, this reflects all renderables
61
        // recursively (including deeply nested rebderables). If we have a non-composite base
62
        // renderable in place, we do nothing since this value resolver only handles composite renderables.
63
        if ($renderable instanceof Form\Domain\Model\FormElements\AbstractSection) {
×
64
            $renderables = $renderable->getElements();
×
65
        } elseif ($renderable instanceof Form\Domain\Model\Renderable\CompositeRenderableInterface) {
×
66
            $renderables = $renderable->getRenderablesRecursively();
×
67
        } else {
68
            $renderables = [];
×
69
        }
70

71
        foreach ($renderables as $index => $child) {
×
72
            if (!$child->isEnabled()) {
×
73
                continue;
×
74
            }
75

NEW
76
            if (!array_key_exists($child->getType() . '.', $configuration)) {
×
NEW
77
                $processedRenderables[] = new Handlebars\SafeString(
×
NEW
78
                    $this->fluidRenderer->render($child, $context->formRuntime),
×
NEW
79
                );
×
80

NEW
81
                continue;
×
82
            }
83

NEW
84
            $childConfiguration = $configuration[$child->getType() . '.'];
×
85

86
            if (is_array($childConfiguration)) {
×
87
                $childViewModel = $this->buildViewModel($child, $context->viewModel->renderingContext);
×
88
            } else {
89
                $childConfiguration = [];
×
90
                $childViewModel = new Domain\Renderable\ViewModel\ViewModel($context->viewModel->renderingContext);
×
91
            }
92

93
            if ($this->cObj !== null) {
×
94
                $this->cObj->data[self::RENDERABLE_INDEX_IDENTIFIER] = $index;
×
95
            }
96

97
            try {
98
                $processedChild = $context->process($childConfiguration, $child, $childViewModel);
×
99
            } finally {
100
                if ($this->cObj !== null) {
×
101
                    unset($this->cObj->data[self::RENDERABLE_INDEX_IDENTIFIER]);
×
102
                }
103
            }
104

105
            if ($processedChild !== null) {
×
106
                $processedRenderables[] = $processedChild;
×
107
            }
108
        }
109

110
        return $processedRenderables;
×
111
    }
112

113
    private function buildViewModel(
×
114
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
115
        Fluid\Core\Rendering\RenderingContext $renderingContext,
116
    ): Domain\Renderable\ViewModel\ViewModel {
117
        foreach ($this->viewModelBuilders as $viewModelBuilder) {
×
118
            if ($viewModelBuilder->supports($renderable)) {
×
119
                return $viewModelBuilder->build($renderable, $renderingContext);
×
120
            }
121
        }
122

123
        return new Domain\Renderable\ViewModel\ViewModel($renderingContext);
×
124
    }
125
}
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