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

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

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

31.15
/Classes/ViewHelpers/Render/UncacheViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Render;
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\CompileWithRenderStatic;
12
use FluidTYPO3\Vhs\Utility\ContentObjectFetcher;
13
use FluidTYPO3\Vhs\Utility\RequestResolver;
14
use FluidTYPO3\Vhs\View\UncacheContentObject;
15
use FluidTYPO3\Vhs\View\UncacheTemplateView;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
18
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
19
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
20
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
21
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
23
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
24

25
/**
26
 * Uncaches partials. Use like ``f:render``.
27
 * The partial will then be rendered each time.
28
 * Please be aware that this will impact render time.
29
 * Arguments must be serializable and will be cached.
30
 */
31
class UncacheViewHelper extends AbstractViewHelper
32
{
33
    use CompileWithRenderStatic;
34

35
    /**
36
     * @var boolean
37
     */
38
    protected $escapeOutput = false;
39

40
    public function initializeArguments(): void
41
    {
42
        $this->registerArgument('partial', 'string', 'Reference to a partial.', true);
7✔
43
        $this->registerArgument('section', 'string', 'Name of section inside the partial to render.');
7✔
44
        $this->registerArgument('arguments', 'array', 'Arguments to pass to the partial.');
7✔
45
        $this->registerArgument(
7✔
46
            'persistPartialPaths',
7✔
47
            'bool',
7✔
48
            'Normally, v:render.uncache will persist the partialRootPaths array that was active when the ViewHelper' .
7✔
49
            'was called, so the exact paths will be reused when rendering the uncached portion of the page output. ' .
7✔
50
            'This is done to ensure that even if you manually added some partial paths through some dynamic means (' .
7✔
51
            'for example, based on a controller argument) then those paths would be used. However, in some cases ' .
7✔
52
            'this will be undesirable - namely when using a cache that is shared between multiple TYPO3 instances ' .
7✔
53
            'and each instance has a different path in the server\'s file system (e.g. load balanced setups). ' .
7✔
54
            'On such setups you should set persistPartialPaths="0" on this ViewHelper to prevent it from caching ' .
7✔
55
            'the resolved partialRootPaths. The ViewHelper will then instead use whichever partialRootPaths are ' .
7✔
56
            'configured for the extension that calls `v:render.uncache`. Note that when this is done, the special ' .
7✔
57
            'use case of dynamic or controller-overridden partialRootPaths is simply not supported.',
7✔
58
            false,
7✔
59
            true
7✔
60
        );
7✔
61
    }
62

63
    /**
64
     * @return mixed
65
     */
66
    public static function renderStatic(
67
        array $arguments,
68
        \Closure $renderChildrenClosure,
69
        RenderingContextInterface $renderingContext
70
    ) {
71
        /** @var RenderingContext $renderingContext */
72
        $templateVariableContainer = $renderingContext->getVariableProvider();
×
73
        $partialArguments = $arguments['arguments'];
×
74
        if (!is_array($partialArguments)) {
×
75
            $partialArguments = (array) $partialArguments;
×
76
        }
77
        if (!isset($partialArguments['settings']) && $templateVariableContainer->exists('settings')) {
×
78
            $partialArguments['settings'] = $templateVariableContainer->get('settings');
×
79
        }
80

81
        $substKey = 'INT_SCRIPT.' . $GLOBALS['TSFE']->uniqueHash();
×
82
        $content = '<!--' . $substKey . '-->';
×
83

84
        $request = RequestResolver::resolveRequestFromRenderingContext($renderingContext);
×
85

86
        if (class_exists(ExtbaseRequestParameters::class) && method_exists($request, 'getAttribute')) {
×
87
            /** @var ExtbaseRequestParameters $extbaseParameters */
88
            $extbaseParameters = $request->getAttribute('extbase');
×
89
        } else {
90
            $extbaseParameters = [
×
91
                'actionName' => RequestResolver::resolveControllerActionNameFromRequest($request),
×
92
                'extensionName' => RequestResolver::resolveControllerExtensionNameFromRequest($request),
×
93
                'controllerName' => RequestResolver::resolveControllerNameFromRequest($request),
×
94
                'controllerObjectName' => RequestResolver::resolveControllerObjectNameFromRequest($request),
×
95
                'pluginName' => RequestResolver::resolvePluginNameFromRequest($request),
×
96
                'format' => RequestResolver::resolveFormatFromRequest($request),
×
97
            ];
×
98
        }
99

100
        $conf = [
×
101
            'userFunc' => UncacheTemplateView::class . '->callUserFunction',
×
102
            'partial' => $arguments['partial'],
×
103
            'section' => $arguments['section'],
×
104
            'arguments' => $partialArguments,
×
105
            'controllerContext' => $extbaseParameters,
×
106
        ];
×
107

108
        if ($arguments['persistPartialPaths'] ?? true) {
×
109
            $conf['partialRootPaths'] = $renderingContext->getTemplatePaths()->getPartialRootPaths();
×
110
        }
111

112
        $contentObjectRenderer = static::getContentObject();
×
113

114
        $content = $contentObjectRenderer->cObjGetSingle(
×
115
            'COA_INT',
×
116
            [
×
117
                '10' => 'USER',
×
118
                '10.' => $conf,
×
119
            ]
×
120
        );
×
121
        return $content;
×
122
    }
123

124
    protected static function getContentObject(): ContentObjectRenderer
125
    {
126
        /** @var ConfigurationManagerInterface $configurationManager */
127
        $configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class);
×
128
        /** @var ContentObjectRenderer|null $contentObject */
129
        $contentObject = ContentObjectFetcher::resolve($configurationManager);
×
130
        if ($contentObject === null) {
×
131
            throw new Exception('v:render.uncache requires a ContentObjectRenderer, none found', 1737808465);
×
132
        }
133
        return $contentObject;
×
134
    }
135
}
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