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

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

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

68.0
/Classes/ViewHelpers/OrViewHelper.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
 * If content is empty use alternative text (can also be LLL:labelname shortcut or LLL:EXT: file paths).
19
 */
20
class OrViewHelper extends AbstractViewHelper
21
{
22
    /**
23
     * @var boolean
24
     */
25
    protected $escapeChildren = false;
26

27
    /**
28
     * @var boolean
29
     */
30
    protected $escapeOutput = false;
31

32
    public function initializeArguments(): void
33
    {
34
        $this->registerArgument('content', 'mixed', 'Input to either use, if not empty');
3✔
35
        $this->registerArgument('alternative', 'mixed', 'Alternative if content is empty, can use LLL: shortcut');
3✔
36
        $this->registerArgument('arguments', 'array', 'Arguments to be replaced in the resulting string');
3✔
37
        $this->registerArgument('extensionName', 'string', 'UpperCamelCase extension name without vendor prefix');
3✔
38
    }
39

40
    /**
41
     * @return mixed
42
     */
43
    public static function renderStatic(
44
        array $arguments,
45
        \Closure $renderChildrenClosure,
46
        RenderingContextInterface $renderingContext
47
    ) {
48
        $content = ($arguments['content'] ?? $renderChildrenClosure()) ?: static::getAlternativeValue(
6✔
49
            $arguments,
6✔
50
            $renderingContext
6✔
51
        );
6✔
52
        return $content;
6✔
53
    }
54

55
    /**
56
     * @return mixed
57
     */
58
    protected static function getAlternativeValue(array $arguments, RenderingContextInterface $renderingContext)
59
    {
60
        /** @var RenderingContext $renderingContext */
61
        $alternative = $arguments['alternative'] ?? null;
3✔
62
        if ($alternative === null) {
3✔
63
            return null;
×
64
        }
65
        $arguments = (array) $arguments['arguments'];
3✔
66
        if (0 === count($arguments)) {
3✔
67
            $arguments = null;
3✔
68
        }
69
        if (0 === strpos($alternative, 'LLL:EXT:')) {
3✔
70
            $alternative = LocalizationUtility::translate($alternative, null, $arguments);
×
71
        } elseif (0 === strpos($alternative, 'LLL:')) {
3✔
72
            $extensionName = $arguments['extensionName'] ?? null;
×
73
            if (null === $extensionName) {
×
74
                $extensionName = RequestResolver::resolveControllerExtensionNameFromRenderingContext($renderingContext);
×
75
            }
76
            $translated = LocalizationUtility::translate(substr($alternative, 4), $extensionName ?: 'core', $arguments);
×
77
            if (null !== $translated) {
×
78
                $alternative = $translated;
×
79
            }
80
        }
81
        return null !== $arguments && !empty($alternative) ? vsprintf($alternative, $arguments) : $alternative;
3✔
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc