Feature: #98914 - TypoScript as request attribute¶
See forge#98914
Description¶
The TYPO3 frontend middleware chain now sets up the request
attribute frontend.typoscript
. This is an instance of
\TYPO3\CMS\Core\TypoScript\FrontendTypoScript
and contains
the calculated TypoScript settings
(formerly "constants") and
sometimes setup
, depending on page cache status.
When a content object or plugin (plugins are content objects as well) needs the current TypoScript, it can retrieve it using this API:
// New substitution of $GLOBALS['TSFE']->tmpl->setup
$frontendTypoScriptSetupArray = $request->getAttribute('frontend.typoscript')->getSetupArray();
The FrontendTypoScript
attribute contains some more getters:
getSettingsTree()
: The TypoScript settings as object tree. This tree is still a bit experimental in TYPO3 v12 and should only be used if really needed for now, it may still change. It is marked internal at the moment.The constants tree is always set up in frontend requests: It is needed early for page cache determination, content objects can expect it to be set.
getFlatSettings()
: The TypoScript settings as flat array. Example TypoScript:mySettings { foo = fooValue bar = barValue }
Result array:
$flatSettings = [ 'mySettings.foo' => 'fooValue', 'mySettings.bar' => 'barValue', ];
The settings array is always set up in frontend requests: It is needed early for page cache determination, content objects can expect it to be set.
getSetupTree()
: The TypoScript setup as object tree. This tree is still a bit experimental in TYPO3 v12 and should only be used if really needed for now, it may still change. It is marked internal at the moment.The setup tree is only set up, if a frontend request could not be satisfied from page cache and a full page content calculation is required, or if a page cache does exist, but contains
USER_INT
orCOA_INT
that have to be calculated for each call. Effectively, when a content object rendering is called, the object can expect the setup object tree to be set.getSetupArray()
: An array representation of the setup tree. This is identical to the oldTYPO3\CMS\Core\TypoScript\TemplateService->setup
that was usually accessed using$GLOBALS['TSFE']->tmpl->setup
.This is the main API to retrieve frontend TypoScript for now. Content objects do receive the current request from the rendering chain and can retrieve the full TypoScript this way, if needed. Note that content objects also retrieve the "local" content object configuration already, an access to the full TypoScript in general is only needed in seldom cases.
The setup array is only set up if a frontend request could not be satisfied from page cache and a full page content calculation is required, or if a page cache does exist but contains
USER_INT
orCOA_INT
that have to be calculated for each call. Effectively, when a content object rendering is called, the object can expect the setup object tree to be set.
Impact¶
This is a substitution especially of the deprecated TYPO3\CMS\Core\TypoScript\TemplateService
,
typical old calls were TypoScriptFrontendController->tmpl
or $GLOBALS['TSFE']->tmpl
,
often reading the setup
property using tmpl->setup
to grab the current TypoScript
setup array. These calls should be avoided, the TemplateService
and the tmpl
property will be removed in TYPO3 v13.