Skip to content

Instantly share code, notes, and snippets.

@sorenmalling
Created October 8, 2024 08:05
Show Gist options
  • Save sorenmalling/b823897b1c3e1e95d0e849aeabbaf4f6 to your computer and use it in GitHub Desktop.
Save sorenmalling/b823897b1c3e1e95d0e849aeabbaf4f6 to your computer and use it in GitHub Desktop.
tsfe.php
<?php
public function tsfe(ServerRequestInterface $request): TypoScriptFrontendController
{
/** @var Site $site */
$site = $request->getAttribute('site');
$language = $request->getAttribute('language') ?? $site->getDefaultLanguage();
$context = clone GeneralUtility::makeInstance(Context::class);
$languageAspect = LanguageAspectFactory::createFromSiteLanguage($language);
$context->setAspect('language', $languageAspect);
$context->setAspect(
'visibility',
GeneralUtility::makeInstance(
VisibilityAspect::class,
false,
false
)
);
$feUser = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
$feUser->user = ['uid' => 0, 'username' => '', 'usergroup' => '' ];
$feUser->fetchGroupData($request);
$pageArguments = GeneralUtility::makeInstance(PageArguments::class, $site->getRootPageId(), '0', []);
/** @var TypoScriptFrontendController $tsfe */
$tsfe = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $context, $site, $language, $pageArguments, $feUser);
$template = GeneralUtility::makeInstance(TemplateService::class, $context, null, $tsfe);
$template->tt_track = false;
$tsfe->tmpl = $template;
$context->setAspect('typoscript', GeneralUtility::makeInstance(TypoScriptAspect::class, true));
$tsfe->newCObj($request);
return $tsfe;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment