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

CPS-IT / handlebars-forms / 22667081007

04 Mar 2026 11:18AM UTC coverage: 0.0%. Remained the same
22667081007

push

github

eliashaeussler
[BUGFIX] Properly access translated label

0 of 1 new or added line in 1 file covered. (0.0%)

0 of 642 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/DataProcessing/Value/NavigationValueResolver.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\DataProcessing\Value;
19

20
use CPSIT\Typo3HandlebarsForms\Domain;
21
use CPSIT\Typo3HandlebarsForms\Fluid\ViewHelperInvocationResult;
22
use CPSIT\Typo3HandlebarsForms\Fluid\ViewHelperInvoker;
23
use TYPO3\CMS\Fluid;
24
use TYPO3\CMS\Form;
25

26
/**
27
 * NavigationValueProcessor
28
 *
29
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
30
 * @license GPL-2.0-or-later
31
 */
32
final readonly class NavigationValueResolver implements ValueResolver
33
{
34
    private const PREVIOUS_PAGE = 'previousPage';
35
    private const NEXT_PAGE = 'nextPage';
36
    private const SUBMIT = 'submit';
37

38
    public function __construct(
×
39
        private ViewHelperInvoker $viewHelperInvoker,
40
    ) {}
×
41

42
    /**
43
     * @return list<mixed>
44
     */
45
    public function resolve(
×
46
        Form\Domain\Model\Renderable\RootRenderableInterface $renderable,
47
        Domain\Renderable\ViewModel\ViewModel $viewModel,
48
        ValueResolutionContext $context = new ValueResolutionContext(),
49
    ): array {
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->getPreviousPage() !== null) {
×
59
            $elements[self::PREVIOUS_PAGE] = $renderable->getPreviousPage();
×
60
        }
61

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

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

72
    /**
73
     * @param array{
74
     *     previousPage?: Form\Domain\Model\FormElements\Page,
75
     *     nextPage?: Form\Domain\Model\FormElements\Page,
76
     *     submit?: Form\Domain\Runtime\FormRuntime,
77
     * } $renderables
78
     * @return list<mixed>
79
     */
80
    private function processElements(
×
81
        array $renderables,
82
        ValueResolutionContext $context,
83
        Fluid\Core\Rendering\RenderingContext $renderingContext,
84
        Form\Domain\Runtime\FormRuntime $formRuntime,
85
    ): array {
86
        $processedElements = [];
×
87

88
        foreach ($renderables as $step => $stepRenderable) {
×
89
            $stepConfiguration = $context[$step . '.'] ?? null;
×
90

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

103
            $processedElement = $context->process($stepConfiguration, $stepRenderable, $stepViewModel);
×
104

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

110
        return $processedElements;
×
111
    }
112

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

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

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

NEW
146
            $buttonResult->tag->addAttribute('label', $labelResult);
×
147
        }
148

149
        return $buttonResult;
×
150
    }
151

152
    public static function getName(): string
×
153
    {
154
        return 'NAVIGATION';
×
155
    }
156
}
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