• 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

86.36
/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\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
 * If content is empty use alternative text (can also be LLL:labelname shortcut or LLL:EXT: file paths).
20
 */
21
class OrViewHelper extends AbstractViewHelper
22
{
23
    use CompileWithContentArgumentAndRenderStatic;
24

25
    /**
26
     * @var boolean
27
     */
28
    protected $escapeChildren = false;
29

30
    /**
31
     * @var boolean
32
     */
33
    protected $escapeOutput = false;
34

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

43
    /**
44
     * @return mixed
45
     */
46
    public static function renderStatic(
47
        array $arguments,
48
        \Closure $renderChildrenClosure,
49
        RenderingContextInterface $renderingContext
50
    ) {
51
        $content = $renderChildrenClosure() ?: static::getAlternativeValue($arguments, $renderingContext);
30✔
52
        return $content;
30✔
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;
24✔
62
        if ($alternative === null) {
24✔
63
            return null;
×
64
        }
65
        $arguments = (array) $arguments['arguments'];
24✔
66
        if (0 === count($arguments)) {
24✔
67
            $arguments = null;
24✔
68
        }
69
        if (0 === strpos($alternative, 'LLL:EXT:')) {
24✔
70
            $alternative = LocalizationUtility::translate($alternative, null, $arguments);
×
71
        } elseif (0 === strpos($alternative, 'LLL:')) {
24✔
72
            $extensionName = $arguments['extensionName'] ?? null;
6✔
73
            if (null === $extensionName) {
6✔
74
                $extensionName = RequestResolver::resolveControllerExtensionNameFromRenderingContext($renderingContext);
6✔
75
            }
76
            $translated = LocalizationUtility::translate(substr($alternative, 4), $extensionName ?: 'core', $arguments);
6✔
77
            if (null !== $translated) {
6✔
78
                $alternative = $translated;
×
79
            }
80
        }
81
        return null !== $arguments && !empty($alternative) ? vsprintf($alternative, $arguments) : $alternative;
24✔
82
    }
83
}
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