Skip to content
Snippets Groups Projects
Commit 2d89d93d authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[TASK] Avoid munging Request in fluid RenderingContext

RenderingContext is *the* state object in fluid.

Fluid was always bound to extbase. There was
quite some magic between the two: For instance,
when extbase calls action "myDetailAction" on
"ListController", fluid looks for template
"List/MyDetail.html". Fluid derived this from
the old extbase request - A request implementation
that existed before PSR-7 handling has been
introduced to the core.

With TYPO3 v11, the extbase request has been turned
into a decorator of the PSR-7 object, and fluid has
been changed to deal with a standard PSR-7 request.
But lots of the fluid related magic tailored to the
extbase request remained. Some blockers to relax this
have been removed already, most notably the extbase
ControllerContext vanished, and the StandaloneView
no longer creates an extbase request in its constructor.

We can now go a step further: The RenderingContext
creates new requests when setControllerAction() and
setControllerName(), even cross-triggered when
setRequest() is called.

This is insane: A rendering engine must never manipulate
request itself, but must expect a proper request to hand
over by the application.

$controllerName and $controllerAction are still important
within fluid - it still derives the template files from it
if no direct template file is given. But there is no
reason to also change the request. All this functionality
is bound to the extbase request only. Extbase
bootstrap *does* create a proper extbase request
already. It can just be hand over as is.
setControllerAction() and setControllerName()
can be called by extbase abstract ActionController
to init fluid properly, reading the values from extbase
request itself. Magic within RenderingContext is no
longer needed.

Resolves: #104471
Related: #96183
Related: #98377
Releases: main
Change-Id: I2090230cc37870c0f2a7107ca2af6370ab786175
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85346


Reviewed-by: default avatarSimon Praetorius <simon@praetorius.me>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarSimon Praetorius <simon@praetorius.me>
parent a1ff91ba
Branches
Tags
No related merge requests found
......@@ -489,6 +489,8 @@ abstract class ActionController implements ControllerInterface
if ($renderingContext instanceof RenderingContext) {
$renderingContext->setRequest($this->request);
}
$renderingContext->setControllerName($this->request->getControllerName());
$renderingContext->setControllerAction($this->request->getControllerActionName());
$templatePaths = $view->getRenderingContext()->getTemplatePaths();
$templatePaths->fillDefaultsByPackageName($this->request->getControllerExtensionKey());
$templatePaths->setFormat($this->request->getFormat());
......
......@@ -19,7 +19,6 @@ namespace TYPO3\CMS\Fluid\Core\Rendering;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver;
use TYPO3\CMS\Fluid\View\TemplatePaths;
use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface;
......@@ -99,10 +98,6 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
$action = substr($action, 0, $dotPosition);
}
$this->controllerAction = $action;
if ($this->request instanceof RequestInterface) {
// @todo: Avoid altogether?!
$this->request = $this->request->withControllerActionName(lcfirst($action));
}
}
/**
......@@ -111,22 +106,16 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
public function setControllerName($controllerName): void
{
$this->controllerName = $controllerName;
if ($this->request instanceof RequestInterface) {
// @todo: Avoid altogether?!
$this->request = $this->request->withControllerName($controllerName);
}
}
public function getControllerName(): string
{
// @todo: Why fallback to request here? This is not consistent!
return $this->request instanceof RequestInterface ? $this->request->getControllerName() : $this->controllerName;
return $this->controllerName;
}
public function getControllerAction(): string
{
// @todo: Why fallback to request here? This is not consistent!
return $this->request instanceof RequestInterface ? $this->request->getControllerActionName() : $this->controllerAction;
return $this->controllerAction;
}
/**
......@@ -137,11 +126,6 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
public function setRequest(?ServerRequestInterface $request): void
{
$this->request = $request;
if ($request instanceof RequestInterface) {
// Set magic if this is an extbase request
$this->setControllerAction($request->getControllerActionName());
$this->setControllerName($request->getControllerName());
}
}
public function getRequest(): ?ServerRequestInterface
......
......@@ -68,6 +68,6 @@ final class RenderingContextTest extends UnitTestCase
$request = new Request($serverRequest);
$subject->setRequest($request);
$subject->setControllerAction($input);
self::assertSame(lcfirst($expected), $subject->getControllerAction());
self::assertSame($expected, $subject->getControllerAction());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment