From 2d89d93d8c93b4c9acf9169c1dda72a417783709 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Wed, 24 Jul 2024 17:45:58 +0200 Subject: [PATCH] [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: Simon Praetorius <simon@praetorius.me> Tested-by: Benni Mack <benni@typo3.org> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Simon Praetorius <simon@praetorius.me> --- .../Mvc/Controller/ActionController.php | 2 ++ .../Core/Rendering/RenderingContext.php | 20 ++----------------- .../Core/Rendering/RenderingContextTest.php | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php b/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php index 80e2faf54a91..acb5451a82b1 100644 --- a/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php +++ b/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php @@ -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()); diff --git a/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContext.php b/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContext.php index d18fcb8fb542..539e1439bb16 100644 --- a/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContext.php +++ b/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContext.php @@ -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 diff --git a/typo3/sysext/fluid/Tests/Unit/Core/Rendering/RenderingContextTest.php b/typo3/sysext/fluid/Tests/Unit/Core/Rendering/RenderingContextTest.php index 55eb9a4b45bb..fb75309d220a 100644 --- a/typo3/sysext/fluid/Tests/Unit/Core/Rendering/RenderingContextTest.php +++ b/typo3/sysext/fluid/Tests/Unit/Core/Rendering/RenderingContextTest.php @@ -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()); } } -- GitLab