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

CPS-IT / handlebars-forms / 22340200704

24 Feb 2026 07:00AM UTC coverage: 0.0%. Remained the same
22340200704

push

github

eliashaeussler
[TASK] Improve namings and extract RENDERABLES to its own value processor

0 of 129 new or added lines in 18 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

0 of 458 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/NavigationValueProcessor.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\DataProcessing;
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 NavigationValueProcessor implements ValueProcessor
33
{
34
    private const PREVIOUS_PAGE = 'previousPage';
35
    private const NEXT_PAGE = 'nextPage';
36
    private const SUBMIT = 'submit';
37

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

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

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

NEW
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
     */
NEW
80
    private function processElements(
×
81
        array $renderables,
82
        ProcessingContext $context,
83
        Fluid\Core\Rendering\RenderingContext $renderingContext,
84
        Form\Domain\Runtime\FormRuntime $formRuntime,
85
    ): array {
NEW
86
        $processedElements = [];
×
87

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

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

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

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

NEW
110
        return $processedElements;
×
111
    }
112

113
    /**
114
     * @param self::* $step
115
     */
NEW
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 {
NEW
122
        $isPage = $pageOrForm instanceof Form\Domain\Model\FormElements\Page;
×
123

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

NEW
133
        $labelResult = $this->viewHelperInvoker->invoke(
×
NEW
134
            $renderingContext,
×
NEW
135
            Form\ViewHelpers\TranslateElementPropertyViewHelper::class,
×
NEW
136
            [
×
NEW
137
                'element' => $isPage ? $formRuntime->getCurrentPage() : $formRuntime,
×
NEW
138
                'renderingOptionProperty' => match ($step) {
×
NEW
139
                    self::PREVIOUS_PAGE => 'previousButtonLabel',
×
NEW
140
                    self::NEXT_PAGE => 'nextButtonLabel',
×
NEW
141
                    self::SUBMIT => 'submitButtonLabel',
×
NEW
142
                },
×
NEW
143
            ],
×
NEW
144
        );
×
145

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

NEW
148
        return $buttonResult;
×
149
    }
150

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