TYPO3 Exception 1666513645 

TYPO3 13.4 - 30th December 2024 

Installation Overview 

It uses the extension tslib_fetce 0.9.2 which uses the FrontendTce class Middleware.

The Issue 

RuntimeException

Setup array has not been initialized. This happens in cached Frontend scope where full TypoScript is not needed by the system.

1st Solution 

Call the method hasSetup before getSetupArray.

uae method hasSetup before getSetupArray
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
   $frontendTypoScript = $request->getAttribute('frontend.typoscript');
   if ($frontendTypoScript->hasSetup()) {
       $typoScriptSetupArray = $frontendTypoScript->getSetupArray();
       // ...
   }
}
Copied!

2nd Solution 

Initialize the setSetupArray before getSetupArray checks the setup array

how the Admin Panel system extension
/**
 * Renders the admin panel - Called in PSR-15 Middleware
 *
 * @see \TYPO3\CMS\Adminpanel\Middleware\AdminPanelRenderer
 */
public function render(ServerRequestInterface $request): string
{
    $resources = ResourceUtility::getResources(['nonce' => $this->requestId->nonce]);

    $backupRequest = null;
    $frontendTypoScript = $request->getAttribute('frontend.typoscript');
    if (!$frontendTypoScript->hasSetup()) {
        // @todo: This is a hack: The admin panel is the only extension that starts
        //        a Fluid view in 'fully cached' scenarios. f:translate() now triggers
        //        the extbase configuration manager in FE, which fetches TS setup from
        //        the Request attribute, which is *usally* always available, *except*
        //        in fully cached scenarios.
        //        See https://review.typo3.org/c/Packages/TYPO3.CMS/+/80732
        //        We still want extbase to crash if it tries to fetch TS setup when it
        //        is not set, so we work around this in the admin panel here.
        //        This should later be resolved by avoiding the dependency to extbase
        //        LocalizationUtility again, when core localization services can do
        //        similar things in FE as well.
        $frontendTypoScript = clone $frontendTypoScript;
        $frontendTypoScript->setSetupArray([]);
        $request = $request->withAttribute('frontend.typoscript', $frontendTypoScript);
        $GLOBALS['TYPO3_REQUEST'] = $request;
    }
}
Copied!

3rd Solution 

Configure the middleware in a way that the initialization of the setup array is executed before the middleware.

myextension/Configuration/RequestMiddlewares.php
use MyDomain\MyExtension\Middleware\XajaxHandler;

return [
    'frontend' => [
        'mydomain/myextension/preprocessing' => [
            'target' =>  XajaxHandler::class,
            'description' => 'Calls to my extension will be processed and no page will be generated.',
            'after' => [
                'typo3/cms-frontend/prepare-tsfe-rendering'
            ],
            'before' => [
                'typo3/cms-frontend/content-length-headers',
            ],
        ],
    ],
];
Copied!