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

CPS-IT / handlebars-forms / 23346221116

20 Mar 2026 02:00PM UTC coverage: 0.0%. Remained the same
23346221116

push

github

web-flow
Merge pull request #13 from CPS-IT/feature/translate-error

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

0 of 870 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/TranslateErrorContentObject.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\Fluid;
21
use Psr\Http\Message;
22
use Symfony\Component\DependencyInjection;
23
use TYPO3\CMS\Extbase;
24
use TYPO3\CMS\Form;
25

26
/**
27
 * TranslateErrorContentObject
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_TRANSLATE_ERROR'])]
33
final class TranslateErrorContentObject extends AbstractHandlebarsFormsContentObject
34
{
NEW
35
    public function __construct(
×
36
        private readonly Fluid\ViewHelperInvoker $viewHelperInvoker,
NEW
37
    ) {}
×
38

NEW
39
    protected function resolve(array $configuration, Context\ValueResolutionContext $context): mixed
×
40
    {
NEW
41
        $errorCode = $configuration['errorCode'] ?? null;
×
42

NEW
43
        if (!is_numeric($errorCode)) {
×
NEW
44
            return null;
×
45
        }
46

NEW
47
        return $this->viewHelperInvoker->invoke(
×
NEW
48
            $context->viewModel->renderingContext,
×
NEW
49
            Form\ViewHelpers\TranslateElementErrorViewHelper::class,
×
NEW
50
            [
×
NEW
51
                'element' => $context->renderable,
×
NEW
52
                'error' => $this->buildError($context, (int)$errorCode),
×
NEW
53
            ],
×
NEW
54
        )->content;
×
55
    }
56

NEW
57
    private function buildError(Context\ValueResolutionContext $context, int $errorCode): Extbase\Error\Error
×
58
    {
NEW
59
        $error = new Extbase\Error\Error('', $errorCode);
×
NEW
60
        $renderable = $context->renderable;
×
61

62
        // Resolve property path from renderable
NEW
63
        if ($renderable instanceof Form\Domain\Model\Renderable\AbstractRenderable) {
×
NEW
64
            $property = $renderable->getRootForm()->getIdentifier() . '.' . $renderable->getIdentifier();
×
65
        } else {
NEW
66
            $property = $renderable->getIdentifier();
×
67
        }
68

NEW
69
        $request = $context->viewModel->renderingContext->getAttribute(Message\ServerRequestInterface::class);
×
NEW
70
        $extbaseRequestParameters = $request->getAttribute('extbase');
×
71

72
        // Early return when content object was requested outside of extbase context
NEW
73
        if (!($extbaseRequestParameters instanceof Extbase\Mvc\ExtbaseRequestParameters)) {
×
NEW
74
            return $error;
×
75
        }
76

NEW
77
        $validationResults = $extbaseRequestParameters->getOriginalRequestMappingResults()->forProperty($property);
×
78

NEW
79
        foreach ($validationResults->getErrors() as $validationError) {
×
NEW
80
            if ($validationError->getCode() === $errorCode) {
×
NEW
81
                return $validationError;
×
82
            }
83
        }
84

NEW
85
        return $error;
×
86
    }
87
}
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