Reputation: 29
The following snippet worked in the plugin for version 8 and 9.
Basically this was used to get typoscript setup from the root template.
protected function getTypoScriptSetup()
{
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageRepository */
$pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
$pageRepository->init(false);
/** @var \TYPO3\CMS\Core\TypoScript\TemplateService $templateService */
$templateService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
$typo3Branch = class_exists(\TYPO3\CMS\Core\Information\Typo3Version::class)
? (new \TYPO3\CMS\Core\Information\Typo3Version())->getBranch()
: TYPO3_branch;
if (version_compare($typo3Branch, '9.0', '<')) {
$templateService->init();
}
$templateService->tt_track = false;
$currentPage = $GLOBALS['TSFE']->id;
if ($currentPage === null) {
// root page is not yet populated
$localTSFE = clone $GLOBALS['TSFE'];
if (version_compare($typo3Branch, '9.5', '>=')) {
$localTSFE->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
}
$localTSFE->determineId();
$currentPage = $localTSFE->id;
}
if (version_compare($typo3Branch, '9.5', '>=')) {
$rootLine = GeneralUtility::makeInstance(RootlineUtility::class, (int)$currentPage)->get();
} else {
$rootLine = $pageRepository->getRootLine((int)$currentPage);
}
$templateService->start($rootLine);
$setup = $templateService->setup;
return $setup;
}
I have been stuck with it for days with no luck. In 10.4 version I am getting an error message at clone $GLOBAL['TSFE'].
Error: "_clone on non-object"
I need to get currentpage information to successfully get typoscript setup from the template. Any other way to acheive this also welcome. I guess I am missing something in v10 changelog.
Upvotes: 0
Views: 6757
Reputation: 10791
Use the context API instead of $GLOBALS['TSFE']
:
see the documentation
As you do not state what data is important to you no further help possible.
Being more specific enables other to be more helpful.
Upvotes: 4