Bug #91682
closedExtbase Repository returns not correct translated data if using several languages
0%
Description
I have to provide data from a repository in different languages in an action and a task. Therefore i call a function in my repository and submit the languageID i want to use. If i use separate requests for each languageId anything works fine. If i use a foreach loop to submit different languageIDs i allways get the data of the first submitted languageID.
Example
/**
* Action in controller: Returns for any language the data of the first submitted languageID.
*
* I'm also using this setup with small changes in execute() of a scheduler-task to create json-files.
* If I use a separate task for each language (providing a single languageID instead using $site->geLanguages() and the foreach loop)
* anything works fine - but using foreach with different languageIDs will always return the data of the first submitted languageID
*/
public function createLanguageDataAction() {
$site = $GLOBALS['TYPO3_REQUEST']->getAttribute('site');
$languages = $site->getLanguages();
$data = [];
foreach($languages as $language) {
$languageID = $language->getLanguageId();
$data[] = $dataRepository->getDataForLanguage($languageID);
}
$this->view->assign('data', $data);
}
/**
* Function in repository
* Minimal setup.
* I tried several combinations of the commented lines
* but if the function is called in loop with different languageIDs none of them returned the correct data
*/
public function getDataForLanguage($languageID) {
$query = $this->createQuery();
$query->getQuerySettings()->setLanguageUid($languageID);
//$query->getQuerySettings()->setRespectSysLanguage(TRUE);
//$query->getQuerySettings()->setLanguageMode(NULL);
//$query->getQuerySettings()->setLanguageOverlayMode(NULL);
//$query->matching(
// $query->logicalAnd(
// $query->equals('sys_language_uid', $languageID)
// )
//);
return $query->execute();
}
Updated by Tymoteusz Motylewski 9 days ago
- Assignee deleted (
Tymoteusz Motylewski)
Updated by Garvin Hicking 9 days ago
- Status changed from New to Closed
Hi!
Sorry for taking some time. Ectbase repositories are often coupled to a fixed request, and keep some state. Iterating through languages like this is not really a goal of that concept.
I would suggest in this case to better work with specific custom queries using the querybuilder, when fetching data that exceeds request boundaries.
Because of this I would like to close the issue, I hope that's fine with you.
Let me know if you believe this is a mistake and we can try to optimize your use case.