Skip to content
Snippets Groups Projects
Commit da7776d7 authored by Benni Mack's avatar Benni Mack
Browse files

[BUGFIX] Do not lose Context in AbstractContentObject

When AbstractContentObject is fetching ->getPageRepository()
but TSFE hasn't been fully initialized yet, the Context
from TSFE should be used, and not the global one.

Resolves: #97951
Releases: main, 11.5
Change-Id: I99880839f5458469e7181467de6a8fb667ef9828
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75147


Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
parent e555cc88
Branches
Tags
No related merge requests found
......@@ -16,8 +16,11 @@
namespace TYPO3\CMS\Frontend\ContentObject;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Contains an abstract class for all tslib content class implementations.
......@@ -69,6 +72,46 @@ abstract class AbstractContentObject
$this->request = $request;
}
public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
{
$this->cObj = $cObj;
}
protected function hasTypoScriptFrontendController(): bool
{
return $this->cObj->getTypoScriptFrontendController() instanceof TypoScriptFrontendController;
}
/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController()
{
if (!$this->hasTypoScriptFrontendController()) {
throw new ContentRenderingException('TypoScriptFrontendController is not available.', 1655723512);
}
return $this->cObj->getTypoScriptFrontendController();
}
/**
* @return PageRepository
*/
protected function getPageRepository()
{
if (!$this->hasTypoScriptFrontendController()) {
return GeneralUtility::makeInstance(PageRepository::class);
}
/** do not lose the used {@link \TYPO3\CMS\Core\Context\Context} of TSFE, if it is currently not fully initialized */
if (!$this->getTypoScriptFrontendController()->sys_page instanceof PageRepository) {
return GeneralUtility::makeInstance(
PageRepository::class,
$this->getTypoScriptFrontendController()->getContext()
);
}
return $this->getTypoScriptFrontendController()->sys_page;
}
/**
* @return PageRenderer
*/
......
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