Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Undefined global variable $TYPO3_REQUEST in vendor/typo3/cms-bac… #516

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Classes/Module/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down