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

FluidTYPO3 / vhs / 28370493008

29 Jun 2026 12:01PM UTC coverage: 69.786% (+0.04%) from 69.744%
28370493008

push

github

NamelessCoder
[TASK] Define strict return types on nearly all ViewHelper public API

A few cases left behind since they require further refactoring.

21 of 25 new or added lines in 11 files covered. (84.0%)

4795 of 6871 relevant lines covered (69.79%)

4.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Classes/ViewHelpers/LViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Core\ViewHelper\AbstractViewHelper;
12
use FluidTYPO3\Vhs\Utility\RequestResolver;
13
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
14
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
15
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
16

17
/**
18
 * ### L (localisation) ViewHelper
19
 *
20
 * An extremely shortened and much more dev-friendly
21
 * alternative to f:translate. Automatically outputs
22
 * the name of the LLL reference if it is not found
23
 * and the default value is not set, making it much
24
 * easier to identify missing labels when translating.
25
 *
26
 * ### Examples
27
 *
28
 * ```
29
 * <v:l>some.label</v:l>
30
 * <v:l key="some.label" />
31
 * <v:l arguments="{0: 'foo', 1: 'bar'}">some.label</v:l>
32
 * ```
33
 */
34
class LViewHelper extends AbstractViewHelper
35
{
36
    /**
37
     * @var boolean
38
     */
39
    protected $escapeChildren = false;
40

41
    /**
42
     * @var boolean
43
     */
44
    protected $escapeOutput = false;
45

46
    public function initializeArguments(): void
47
    {
48
        $this->registerArgument('key', 'string', 'Translation Key');
×
49
        $this->registerArgument(
×
50
            'default',
×
51
            'string',
×
52
            'if the given locallang key could not be found, this value is used. If this argument is not set, ' .
×
53
            'child nodes will be used to render the default'
×
54
        );
×
55
        $this->registerArgument(
×
56
            'htmlEscape',
×
57
            'boolean',
×
58
            'TRUE if the result should be htmlescaped. This won\'t have an effect for the default value'
×
59
        );
×
60
        $this->registerArgument('arguments', 'array', 'Arguments to be replaced in the resulting string');
×
61
        $this->registerArgument('extensionName', 'string', 'UpperCamelCased extension key (for example BlogExample)');
×
62
    }
63

64
    public static function renderStatic(
65
        array $arguments,
66
        \Closure $renderChildrenClosure,
67
        RenderingContextInterface $renderingContext
68
    ): string {
69
        /** @var RenderingContext $renderingContext */
70
        /** @var string|null $default */
71
        $default = $arguments['default'];
×
72
        $htmlEscape = (bool) $arguments['htmlEscape'];
×
73
        /** @var string|null $extensionName */
74
        $extensionName = $arguments['extensionName'];
×
75
        /** @var array|null $translationArguments */
76
        $translationArguments = $arguments['arguments'];
×
77
        /** @var string $id */
78
        $id = $arguments['key'] ?? $renderChildrenClosure();
×
79
        if (empty($default)) {
×
80
            $default = $id;
×
81
        }
82
        if (empty($extensionName)) {
×
83
            $extensionName = RequestResolver::resolveControllerExtensionNameFromRenderingContext($renderingContext);
×
84
        }
85
        /** @var string|null $value */
86
        $value = LocalizationUtility::translate((string) $id, $extensionName, $translationArguments);
×
87
        if (empty($value)) {
×
88
            $value = $default;
×
89
            if (!empty($translationArguments)) {
×
90
                $value = vsprintf($value, $translationArguments);
×
91
            }
92
        } elseif ($htmlEscape) {
×
93
            $value = htmlspecialchars((string) $value);
×
94
        }
NEW
95
        return (string) $value;
×
96
    }
97
}
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