From cf1458324c3d4be615adbb917612ebb4bb91442d Mon Sep 17 00:00:00 2001 From: Martin Kristensen Date: Thu, 22 Aug 2024 11:05:04 +0200 Subject: [PATCH] fix: Undefined global variable $TYPO3_REQUEST in vendor/typo3/cms-backend/Classes/Template/ModuleTemplate.php --- Classes/Module/MainController.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 1b2989a0f..4359adea8 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -26,6 +26,10 @@ use TYPO3\CMS\Core\Type\Bitmask\Permission; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; +use TYPO3\CMS\Core\Http\ServerRequest; +use TYPO3\CMS\Core\Site\SiteFinder; class MainController { @@ -78,6 +82,22 @@ public function __construct( IconFactory $iconFactory = null, PageRenderer $pageRenderer = null ) { + //create context for CLI + if (empty($GLOBALS['TYPO3_REQUEST'])) { + $context = GeneralUtility::makeInstance(Context::class); + // Retrieve site and site language from context + $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); + $site = $siteFinder->getSiteByPageId(1); + $siteLanguageId = $context->getPropertyFromAspect('language', 'id'); + $siteLanguage = $site->getLanguageById($siteLanguageId); + $request = new ServerRequest(new Uri((string)$siteLanguage->getBase())); + $request = $request->withAttribute('site', $site); + $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); + $request = $request->withAttribute('language', $siteLanguage); + $request = $request->withQueryParams(['id' => $site->getRootPageId()]); + $GLOBALS['TYPO3_REQUEST'] = $request; + } + $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); $this->iconFactory = $iconFactory ?? GeneralUtility::makeInstance(IconFactory::class); $this->pageRenderer = $pageRenderer ?? GeneralUtility::makeInstance(PageRenderer::class);