I've searched and debugged the last couple of days how to obtain the translated version of a DomainModel object in a CommandController in Typo3 v8.7.
In Typo3 4.5/4.7 I've done the following: - input: DomainModel in default language - build a query that finds the record with the l10n_parent matching the given domain model - obtain a new domain model with the desired sys_language_uid
Unfortunately this does not work in Typo3 v8.7 any more. I always get the domain model for the default language.
I've traced this down to the method Typo3DbBackend::doLanguageAndWorkspaceOverlay
called via Typo3DbBackend::getObjectDataByQuery
The query returns the correct (translated) row (seen in the debugger and also the mysql query log), but then the variable
$row
gets overwritten in doLanguageAndWorkspaceOverlay
no matter how I
set the querySettings setLanguageOverlayMode
and setLanguageMode
.
So what is the correct way to get a translated domain model in a CommandController?
UPDATE:
I think I'm a step further. If I add ->setQueryLanguage(1)
to the query settings, doLanguageAndWorkspaceOverlay()
tries to fetch the translated record for language = 1. But in order to succeed I need to trick the FrontendGroupRestriction
class by setting $GLOBALS['TSFE']->gr_list = "0,-2";
.
The array returned by doLanguageAndWorkspaceOverlay()
now contains all translated entries, except the uid
, which is still the uid
from the record in the main language. The uid
of the translated record is stored in _LOCALIZED_UID
.
Now my problem now is that I still get the record in the main laguage because DataMapper->mapSingleRow()
(called via DataMapper->map()
) has some kind of object cache and thus returns the object in the default language (because the uid
is still the one of the record in the main language).
All this seems a little hackish. So again my question: what is the correct way to get a translated domain model in a CommandController?
thanks, mika
p.s.: I've set up the second language in the backend and creating a translated record works just fine. My question is just how to I get an existing translated record in a CommandController.