Skip to content

Commit

Permalink
[BUGFIX] Avoid circular reference of COR and ServerRequest
Browse files Browse the repository at this point in the history
While the initial idea to store the current ContentObjectRender
(cObj) instance in a request attribute, to pass it along to code
that requires both, the request and a cObj, is solid, we missed
that cObj itself does not require to hold the request as attribute.

The patch changes this: The request attribute is only set
for ContentObjects, as these are actually responsible for
rendering and eventually evaluating a request or the cObj
instance.

This makes sure, that an instance of cObj is available for
Extbase plugins as well as for Fluid view helpers, which can
access the request via RenderingContext.

By changing the concept slightly, all places that previously added
the cObj to the request can be removed in favor of doing so only
in AbstractContentObject and ContentObjectRenderer::callUserFunction.
The latter is at least required for TypoScript using the old way of
calling Extbase plugins with USER and it's userFunc property.

The circular reference is now removed, by not passing the request
that contains the cObj attribute to the cObj itself. This means:

* When a cObj is available, one can obtain the request using its getter
* Such request objects, do NOT contain an attribute containing the cObj
* The cObj request attribute can now be obtained in all content objects
  (such as EXTBASEPLUGIN or FLUIDTEMPLATE) and user functions, that are
  called from be ContentObjectRenderer.

Releases: main, 12.4
Resolves: #101170
Resolves: #100872
Related: #100623
Change-Id: I6acb1a92c8b02f1be2f3a396fe9d9465d6482033
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79519
Reviewed-by: Benni Mack <[email protected]>
Tested-by: core-ci <[email protected]>
Reviewed-by: Christian Kuhn <[email protected]>
Tested-by: Benni Mack <[email protected]>
Tested-by: Christian Kuhn <[email protected]>
  • Loading branch information
helhum authored and bmack committed Aug 2, 2023
1 parent 1e72355 commit 34bacee
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Classes/ViewHelpers/CObjectViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
/** @var RenderingContext $renderingContext */
$request = $renderingContext->getRequest();
$contentObjectRenderer = self::getContentObjectRenderer($request);
$contentObjectRenderer->setRequest($request->withAttribute('currentContentObject', $contentObjectRenderer));
$contentObjectRenderer->setRequest($request);
$tsfeBackup = null;
if (!isset($GLOBALS['TSFE']) || !($GLOBALS['TSFE'] instanceof TypoScriptFrontendController)) {
$tsfeBackup = self::simulateFrontendEnvironment();
Expand Down Expand Up @@ -216,7 +216,12 @@ protected static function getContentObjectRenderer(ServerRequestInterface $reque
GeneralUtility::makeInstance(FrontendUserAuthentication::class)
);
}
return GeneralUtility::makeInstance(ContentObjectRenderer::class, $tsfe);
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class, $tsfe);
$parent = $request->getAttribute('currentContentObject');
if ($parent instanceof ContentObjectRenderer) {
$contentObjectRenderer->setParent($parent->data, $parent->currentRecord);
}
return $contentObjectRenderer;
}

/**
Expand Down

0 comments on commit 34bacee

Please sign in to comment.