Skip to content

Commit

Permalink
[FEATURE] Add toggle to prevent v:render.uncache from persisting part…
Browse files Browse the repository at this point in the history
…ial paths

Close: #1830
  • Loading branch information
NamelessCoder committed Jul 12, 2023
1 parent a9ae125 commit 258949e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Classes/View/UncacheTemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function callUserFunction(string $postUserFunc, array $conf, string $cont
$this->prepareContextsForUncachedRendering($renderingContext);
if (!empty($conf['partialRootPaths'])) {
$renderingContext->getTemplatePaths()->setPartialRootPaths($conf['partialRootPaths']);
} elseif ($parameters['extensionName'] ?? false) {
$renderingContext->getTemplatePaths()->fillDefaultsByPackageName($parameters['extensionName']);
}
return $this->renderPartialUncached($renderingContext, $partial, $section, $arguments);
}
Expand Down
35 changes: 28 additions & 7 deletions Classes/ViewHelpers/Render/UncacheViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ public function initializeArguments(): void
$this->registerArgument('partial', 'string', 'Reference to a partial.', true);
$this->registerArgument('section', 'string', 'Name of section inside the partial to render.');
$this->registerArgument('arguments', 'array', 'Arguments to pass to the partial.');
$this->registerArgument(
'persistPartialPaths',
'bool',
'Normally, v:render.uncache will persist the partialRootPaths array that was active when the ViewHelper' .
'was called, so the exact paths will be reused when rendering the uncached portion of the page output. ' .
'This is done to ensure that even if you manually added some partial paths through some dynamic means (' .
'for example, based on a controller argument) then those paths would be used. However, in some cases ' .
'this will be undesirable - namely when using a cache that is shared between multiple TYPO3 instances ' .
'and each instance has a different path in the server\'s file system (e.g. load balanced setups). ' .
'On such setups you should set persistPartialPaths="0" on this ViewHelper to prevent it from caching ' .
'the resolved partialRootPaths. The ViewHelper will then instead use whichever partialRootPaths are ' .
'configured for the extension that calls `v:render.uncache`. Note that when this is done, the special ' .
'use case of dynamic or controller-overridden partialRootPaths is simply not supported.',
false,
true
);
}

/**
Expand Down Expand Up @@ -76,17 +92,22 @@ public static function renderStatic(
];
}

$conf = [
'partial' => $arguments['partial'],
'section' => $arguments['section'],
'arguments' => $partialArguments,
'controllerContext' => $extbaseParameters,
];

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

$GLOBALS['TSFE']->config['INTincScript'][$substKey] = [
'type' => 'POSTUSERFUNC',
'cObj' => serialize(GeneralUtility::makeInstance(UncacheContentObject::class, $GLOBALS['TSFE']->cObj)),
'postUserFunc' => 'render',
'conf' => [
'partial' => $arguments['partial'],
'section' => $arguments['section'],
'arguments' => $partialArguments,
'partialRootPaths' => $renderingContext->getTemplatePaths()->getPartialRootPaths(),
'controllerContext' => $extbaseParameters,
],
'conf' => $conf,
'content' => $content
];

Expand Down

0 comments on commit 258949e

Please sign in to comment.