In V12 the TemplateService
and TypoScriptParser
classes have been marked as deprecated (#99020 - Deprecate TypoScript/TemplateService). The migration advice given there is very scarce (FE scope with PSR-7 request) and frankly unsatisfactory.
How can you read the TypoScript configuration of a plugin (something like plugin.tx_myplugin_pi1 { ... }
), if you're not in FE context, e.g. in a middleware, console command or BE module? Sometimes you also want to read the TS config of a different extension.
And yes, I know, a plugin is a FE content element and is executed in the context of a specific page (for which there may be a series of inherited TS templates in the rootline) etc. etc.
But there are still valid scenarios where you need this. Let's say we have a console command that sends data generated by a plugin to a remote API and we want to process the data with the same settings that are active on the page, where the data is generated in the first place. If the console command has a command line parameter for the uid of that page, it shouldn't be a problem to get that specific TS configuration.
So far, I've used helper methods that might have looked something like this:
private function getTsConf($pageUid, $pluginName = 'tx_myplugin_pi1') {
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageUid);
$rootline = $rootlineUtility->get();
$templateService = GeneralUtility::makeInstance(TemplateService::class);
$templateService->tt_track = 0;
$templateService->runThroughTemplates($rootline);
$templateService->generateConfig();
$tsService = GeneralUtility::makeInstance(TypoScriptService::class);
return isset($templateService->setup['plugin.'][$pluginName.'.'])
? $tsService->convertTypoScriptArrayToPlainArray($templateService->setup['plugin.'][$pluginName.'.'])
: [];
}
So what are you supposed to do in such a case, if TemplateService
is no longer available?
For me, this is a problem I seem to encounter in almost every project. I really think, this is a standard task that should be easy to deal with. But I feel there is a lack of documentation for non-FE scenarios.
There is currently no factory to retrieve FE TS for a specific page.
The code in question has to be extracted from TypoScriptFrontendController, which needs an extraction of the 'cache' related stuff first. We'll continue to work on this in v13, but v12 will not have a simple solution.
I would have loved a couple more patches in this area for v12, but it was simply too much, given the time and release restrictions and lots of old code laying around. We're just now doing next steps in v13, I hope we'll end up with an easy to use API in v13 when lots of surrounding dust has settled as well.
I see these alternatives in v12:
When doing a FE request from within BE or CLI, create a request object, feed it to Frontend/Application (that's called a sub request, the FE error handling and FE functionals tests do similar things) to retrieve a Response. This will trigger the entire FE chain including TS calculations.
Use extbase ConfigurationManager to retrieve FE TS. ConfigurationManager is a technical debt itself, but it's hard to get rid of it and will continue to stay for a while after we mitigated some of it's flaws in v12.
Use old deprecated TS class in v12 and switch to a better solution with v13.
Copy code from TypoScriptFrontendController getFromCache() to your extension, maybe streamline / shorten it a bit, when you don't need so complex cache mechanics. It's longish, but well documented ... it should be possible to follow and understand by looking at it.