• 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

90.91
/Classes/ViewHelpers/Menu/DeferredViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Menu;
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\Traits\ArgumentOverride;
12
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
13

14
/**
15
 * ### Page: Deferred menu rendering ViewHelper
16
 *
17
 * Place this ViewHelper inside any other ViewHelper which
18
 * has been configured with the `deferred` attribute set to
19
 * TRUE - this will cause the output of the parent to only
20
 * contain the content of this ViewHelper.
21
 */
22
class DeferredViewHelper extends AbstractMenuViewHelper
23
{
24
    use ArgumentOverride;
25

26
    public function initializeArguments(): void
27
    {
28
        parent::initializeArguments();
3✔
29
        $this->overrideArgument(
3✔
30
            'as',
3✔
31
            'string',
3✔
32
            'If used, stores the menu pages as an array in a variable named according to this value and renders ' .
3✔
33
            'the tag content - which means automatic rendering is disabled if this attribute is used'
3✔
34
        );
3✔
35
    }
36

37
    public function render(): string
38
    {
39
        $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
3✔
40
        /** @var string $as */
41
        $as = $this->arguments['as'];
3✔
42
        if (!$viewHelperVariableContainer->exists(AbstractMenuViewHelper::class, 'deferredArray')) {
3✔
43
            return '';
×
44
        }
45
        if (!$viewHelperVariableContainer->exists(AbstractMenuViewHelper::class, 'deferredString')) {
3✔
46
            return '';
×
47
        }
48
        if (null === $as) {
3✔
49
            $content = $viewHelperVariableContainer->get(AbstractMenuViewHelper::class, 'deferredString');
3✔
50
            $this->unsetDeferredVariableStorage();
3✔
51
            return is_scalar($content) ? (string) $content : '';
3✔
52
        } elseif (empty($as)) {
3✔
53
            throw new Exception('An "as" attribute was used but was empty - use a proper string value', 1370096373);
×
54
        }
55

56
        $variableProvider = $this->renderingContext->getVariableProvider();
3✔
57

58
        if ($variableProvider->exists($as)) {
3✔
59
            $backupVariable = $variableProvider->get($as);
3✔
60
            $variableProvider->remove($as);
3✔
61
        }
62
        $variableProvider->add(
3✔
63
            $as,
3✔
64
            $viewHelperVariableContainer->get(AbstractMenuViewHelper::class, 'deferredArray')
3✔
65
        );
3✔
66
        $this->unsetDeferredVariableStorage();
3✔
67
        $content = $this->renderChildren();
3✔
68
        $variableProvider->remove($as);
3✔
69
        if (isset($backupVariable)) {
3✔
70
            $variableProvider->add($as, $backupVariable);
3✔
71
        }
72

73
        return is_scalar($content) ? (string) $content : '';
3✔
74
    }
75
}
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