Rest: 3.5.0 and 4.0
Typo3: 9.5.5
Background: with version 9.2, the Site Handling was introduced and PSR-15 middlewares were introduced.
Problem description
In my specific case I have a site with a multi domain/single tree setup. The language is determined via the URL, e.g. www.domain.de maps to Language ID 0 and www.domain.com to Language ID 1.
The REST extension does not support this, it seems. The Language ID is always 0, no matter which domain used.
Findings
There is a middleware (web/typo3/sysext/frontend/Classes/Middleware/SiteResolver.php) which is taking care of resolving the language, which is not processed when the REST extension is used, since the eID handler (web/typo3/sysext/frontend/Classes/Middleware/EidHandler.php) is processed before the SiteResolver.
I tweaked web/typo3conf/ext/rest/Classes/Bootstrap.php::setRequestedLanguage the following way to make it work:
private function setRequestedLanguage(TypoScriptFrontendController $frontendController)
{
$request = $GLOBALS['TYPO3_REQUEST'];
/** @var SiteRouteResult $routeResult */
$routeResult = GeneralUtility::makeInstance(SiteMatcher::class)->matchRequest($request);
$request = $request->withAttribute('site', $routeResult->getSite());
$request = $request->withAttribute('language', $routeResult->getLanguage());
$request = $request->withAttribute('routing', $routeResult);
$GLOBALS['TYPO3_REQUEST'] = $request;
// Set language if defined
$requestedLanguageUid = $routeResult->getLanguage()->getLanguageId()
?? $this->getRequestedLanguageUid($frontendController);
if (null !== $requestedLanguageUid) {
$frontendController->config['config']['sys_language_uid'] = $requestedLanguageUid;
// Add LinkVars and language to work with correct localized labels
$frontendController->config['config']['linkVars'] = 'L(int)';
$frontendController->config['config']['language'] = $this->getRequestedLanguageCode();
}
}
however this duplicates the code from the SiteResolver middleware. Ideally the SiteResolver middleware should be processed before Bootstrap::init() is called, but I'm not sure if this is possible. I tried to change the order of the Typo3 middlewares accordingly, but without success. Potentially this could also cause side effects.
Using the L parameter is actually no option, since it is deprecated with the introduction of the new site handling.
Before digging deeper into this, I wanted to check with you if this is a known issue already.
And: Thanks for your efforts on this extension!