Skip to content

Commit

Permalink
Handle context outside of extbase extensions
Browse files Browse the repository at this point in the history
In case there is no Extbase ControllerContext, do not convert ServerRequest to Extbase Request. Instead, attach the ServerRequest directly to the RenderingContext
  • Loading branch information
Ceremony64 authored Feb 13, 2024
1 parent 12a770b commit 4ae25be
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions Classes/View/UncacheTemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function callUserFunction(string $postUserFunc, array $conf): string
return '';
}

if (class_exists(ExtbaseRequestParameters::class)) {
if ($parameters instanceof ExtbaseRequestParameters) {
// Typo3 v11+ within extbase extension
$renderingContext = $this->createRenderingContextWithRenderingContextFactory();

if (method_exists($renderingContext, 'setRequest')) {
Expand All @@ -44,46 +45,48 @@ public function callUserFunction(string $postUserFunc, array $conf): string
);
}
} else {
/** @var ControllerContext $controllerContext */
$controllerContext = GeneralUtility::makeInstance(ControllerContext::class);
/** @var Request $request */
$request = GeneralUtility::makeInstance(Request::class);
$controllerContext->setRequest($request);

/** @var UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($request);
$controllerContext->setUriBuilder($uriBuilder);

if ($parameters) {
if (method_exists($request, 'setControllerActionName')) {
$request->setControllerActionName($parameters['actionName']);
}

if (method_exists($request, 'setControllerExtensionName')) {
$request->setControllerExtensionName($parameters['extensionName']);
}

if (method_exists($request, 'setControllerName')) {
$request->setControllerName($parameters['controllerName']);
}

if (method_exists($request, 'setControllerObjectName')) {
$request->setControllerObjectName($parameters['controllerObjectName']);
}

if (method_exists($request, 'setPluginName')) {
$request->setPluginName($parameters['pluginName']);
}

if (method_exists($request, 'setFormat')) {
$request->setFormat($parameters['format']);
if (class_exists(RenderingContextFactory::class)) {
// Typo3 v11+
$renderingContext = $this->createRenderingContextWithRenderingContextFactory();
if (method_exists($renderingContext, 'setRequest')) {
$renderingContext->setRequest($GLOBALS['TYPO3_REQUEST']);
}
} else {
// Typo3 v10
/** @var ControllerContext $controllerContext */
$controllerContext = GeneralUtility::makeInstance(ControllerContext::class);
/** @var Request $request */
$request = GeneralUtility::makeInstance(Request::class);
$controllerContext->setRequest($request);

/** @var UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($request);
$controllerContext->setUriBuilder($uriBuilder);
if ($parameters) {
if (method_exists($request, 'setControllerActionName')) {
$request->setControllerActionName($parameters['actionName']);
}
if (method_exists($request, 'setControllerExtensionName')) {
$request->setControllerExtensionName($parameters['extensionName']);
}
if (method_exists($request, 'setControllerName')) {
$request->setControllerName($parameters['controllerName']);
}
if (method_exists($request, 'setControllerObjectName')) {
$request->setControllerObjectName($parameters['controllerObjectName']);
}
if (method_exists($request, 'setPluginName')) {
$request->setPluginName($parameters['pluginName']);
}
if (method_exists($request, 'setFormat')) {
$request->setFormat($parameters['format']);
}
}
/** @var RenderingContext $renderingContext */
$renderingContext = GeneralUtility::makeInstance(RenderingContext::class);
$renderingContext->setControllerContext($controllerContext);
}

/** @var RenderingContext $renderingContext */
$renderingContext = GeneralUtility::makeInstance(RenderingContext::class);
$renderingContext->setControllerContext($controllerContext);
}

$this->prepareContextsForUncachedRendering($renderingContext);
Expand Down

0 comments on commit 4ae25be

Please sign in to comment.