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

FluidTYPO3 / vhs / 10213662489

02 Aug 2024 09:55AM UTC coverage: 72.717% (-0.05%) from 72.762%
10213662489

push

github

NamelessCoder
[TER] 7.0.4

5533 of 7609 relevant lines covered (72.72%)

13.49 hits per line

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

90.32
/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\Utility\RequestResolver;
12
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
13
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
14
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
16
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
17

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

39
    /**
40
     * @var boolean
41
     */
42
    protected $escapeChildren = false;
43

44
    /**
45
     * @var boolean
46
     */
47
    protected $escapeOutput = false;
48

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

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