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

CPS-IT / handlebars-forms / 23132858873

16 Mar 2026 07:36AM UTC coverage: 0.0%. Remained the same
23132858873

push

github

web-flow
Merge pull request #10 from CPS-IT/feature/cobj

[FEATURE] Convert value resolvers to context-aware content objects

0 of 88 new or added lines in 11 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

0 of 696 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/NavigationContentObject.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 CPSIT\Typo3HandlebarsForms\Fluid\ViewHelperInvocationResult;
22
use CPSIT\Typo3HandlebarsForms\Fluid\ViewHelperInvoker;
23
use Symfony\Component\DependencyInjection;
24
use TYPO3\CMS\Fluid;
25
use TYPO3\CMS\Form;
26

27
/**
28
 * NavigationContentObject
29
 *
30
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
31
 * @license GPL-2.0-or-later
32
 */
33
#[DependencyInjection\Attribute\AutoconfigureTag('frontend.contentobject', ['identifier' => 'HBS_NAVIGATION'])]
34
final class NavigationContentObject extends AbstractHandlebarsFormsContentObject
35
{
36
    private const PREVIOUS_PAGE = 'previousPage';
37
    private const NEXT_PAGE = 'nextPage';
38
    private const SUBMIT = 'submit';
39

40
    public function __construct(
×
41
        private readonly ViewHelperInvoker $viewHelperInvoker,
42
    ) {}
×
43

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

52
        // We cannot process navigation within a concrete form element
53
        if (!($renderable instanceof Form\Domain\Runtime\FormRuntime)) {
×
54
            return [];
×
55
        }
56

57
        // Add previous page button
58
        if ($renderable->getPreviousEnabledPage() !== null) {
×
59
            $elements[self::PREVIOUS_PAGE] = $renderable->getPreviousEnabledPage();
×
60
        }
61

62
        // Add next page OR submit button
63
        if ($renderable->getNextEnabledPage() !== null) {
×
64
            $elements[self::NEXT_PAGE] = $renderable->getNextEnabledPage();
×
65
        } else {
66
            $elements[self::SUBMIT] = $renderable;
×
67
        }
68

NEW
69
        return $this->processElements($elements, $configuration, $context, $renderable);
×
70
    }
71

72
    /**
73
     * @param array<self::*, Form\Domain\Model\FormElements\Page|Form\Domain\Runtime\FormRuntime> $renderables
74
     * @param array<string, mixed> $configuration
75
     * @return list<mixed>
76
     */
77
    private function processElements(
×
78
        array $renderables,
79
        array $configuration,
80
        Context\ValueResolutionContext $context,
81
        Form\Domain\Runtime\FormRuntime $formRuntime,
82
    ): array {
NEW
83
        $renderingContext = $context->viewModel->renderingContext;
×
84
        $processedElements = [];
×
85

86
        foreach ($renderables as $step => $stepRenderable) {
×
NEW
87
            $stepConfiguration = $configuration[$step . '.'] ?? null;
×
88

89
            if (is_array($stepConfiguration)) {
×
90
                $buttonResult = $this->processButton($renderingContext, $stepRenderable, $formRuntime, $step);
×
91
                $stepViewModel = new Domain\Renderable\ViewModel\ViewModel(
×
92
                    $renderingContext,
×
93
                    $buttonResult->content,
×
94
                    $buttonResult->tag,
×
95
                );
×
96
            } else {
97
                $stepConfiguration = [];
×
98
                $stepViewModel = new Domain\Renderable\ViewModel\ViewModel($renderingContext, null);
×
99
            }
100

101
            $processedElement = $context->process($stepConfiguration, $stepRenderable, $stepViewModel);
×
102

103
            if ($processedElement !== null) {
×
104
                $processedElements[] = $processedElement;
×
105
            }
106
        }
107

108
        return $processedElements;
×
109
    }
110

111
    /**
112
     * @param self::* $step
113
     */
114
    private function processButton(
×
115
        Fluid\Core\Rendering\RenderingContext $renderingContext,
116
        Form\Domain\Model\FormElements\Page|Form\Domain\Runtime\FormRuntime $pageOrForm,
117
        Form\Domain\Runtime\FormRuntime $formRuntime,
118
        string $step,
119
    ): ViewHelperInvocationResult {
120
        $isPage = $pageOrForm instanceof Form\Domain\Model\FormElements\Page;
×
121
        $labelRenderable = $isPage ? $formRuntime->getCurrentPage() : $formRuntime;
×
122

123
        $buttonResult = $this->viewHelperInvoker->invoke(
×
124
            $renderingContext,
×
125
            Fluid\ViewHelpers\Form\ButtonViewHelper::class,
×
126
            [
×
127
                'property' => '__currentPage',
×
128
                'value' => $isPage ? $pageOrForm->getIndex() : count($pageOrForm->getPages()),
×
129
            ],
×
130
        );
×
131

132
        if ($labelRenderable !== null) {
×
133
            $labelResult = $this->viewHelperInvoker->translateElementProperty(
×
134
                $renderingContext,
×
135
                $labelRenderable,
×
136
                match ($step) {
×
137
                    self::PREVIOUS_PAGE => 'previousButtonLabel',
×
138
                    self::NEXT_PAGE => 'nextButtonLabel',
×
139
                    self::SUBMIT => 'submitButtonLabel',
×
140
                },
×
141
                'renderingOptionProperty',
×
142
            );
×
143

144
            $buttonResult->tag->addAttribute('label', $labelResult);
×
145
        }
146

147
        return $buttonResult;
×
148
    }
149
}
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