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

CPS-IT / handlebars-forms / 23788866234

31 Mar 2026 08:52AM UTC coverage: 0.659% (-0.06%) from 0.72%
23788866234

push

github

web-flow
Merge pull request #18 from CPS-IT/feature/view-models

0 of 163 new or added lines in 33 files covered. (0.0%)

7 of 1062 relevant lines covered (0.66%)

0.03 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
{
35
    public function __construct(
×
36
        private readonly Fluid\ViewHelperInvoker $viewHelperInvoker,
37
    ) {}
×
38

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

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

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

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

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

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

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

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

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

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