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

CPS-IT / handlebars-forms / 23294489338

19 Mar 2026 12:18PM UTC coverage: 0.0%. Remained the same
23294489338

push

github

eliashaeussler
[FEATURE] Populate current index when iterating children and renderables

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

34 existing lines in 2 files now uncovered.

0 of 841 relevant lines covered (0.0%)

0.0 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\Renderable\ViewModel\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
    ) {}
×
43

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

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

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

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

74
            $childConfiguration = $configuration[$child->getType() . '.'] ?? null;
×
75

76
            if (is_array($childConfiguration)) {
×
77
                $childViewModel = $this->buildViewModel($child, $context->viewModel->renderingContext);
×
78
            } else {
79
                $childConfiguration = [];
×
80
                $childViewModel = new Domain\Renderable\ViewModel\ViewModel($context->viewModel->renderingContext);
×
81
            }
82

NEW
83
            if ($this->cObj !== null) {
×
NEW
84
                $this->cObj->data[self::RENDERABLE_INDEX_IDENTIFIER] = $index;
×
85
            }
86

87
            try {
NEW
88
                $processedChild = $context->process($childConfiguration, $child, $childViewModel);
×
89
            } finally {
NEW
90
                if ($this->cObj !== null) {
×
NEW
91
                    unset($this->cObj->data[self::RENDERABLE_INDEX_IDENTIFIER]);
×
92
                }
93
            }
94

95
            if ($processedChild !== null) {
×
96
                $processedRenderables[] = $processedChild;
×
97
            }
98
        }
99

100
        return $processedRenderables;
×
101
    }
102

103
    private function buildViewModel(
×
104
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
105
        Fluid\Core\Rendering\RenderingContext $renderingContext,
106
    ): Domain\Renderable\ViewModel\ViewModel {
107
        foreach ($this->viewModelBuilders as $viewModelBuilder) {
×
108
            if ($viewModelBuilder->supports($renderable)) {
×
109
                return $viewModelBuilder->build($renderable, $renderingContext);
×
110
            }
111
        }
112

113
        return new Domain\Renderable\ViewModel\ViewModel($renderingContext);
×
114
    }
115
}
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