Bug #78026
closedget translation of extbase object / persistenceSession does not track languages
0%
Description
When getting a translation of an existing extbase object the original object is returned.
The usecase is to show the translated record together with the original record on a page.
The problem is that the persistenceSession registers an object based on uid and classname, but the language is not respected in this session. Therefore when the datamapper is invoking the method 'hasIdentifier' on this class (typo3/sysext/extbase/Classes/Persistence/Generic/Session.php) this returns true and the original object is retrieved from the persistenceSession.
A workaround for this is to inject the persistenceSession in the repository and unregister the object in the persistenceSession:
/**
* persistenceSession
*
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Session
* @inject
*/
protected $persistenceSession = null;
- @param Item $item
- @param int $languageUid
- @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findTranslationOfItem($item, $languageUid) {
$query = $this->createQuery();
$querySettings = $query->getQuerySettings();
$querySettings->setLanguageUid($languageUid);
$query->setQuerySettings($querySettings);
$query->matching($query->equals('uid', $item->getUid()));
//Unregister the orignal object else the orignal will be returned
$this->persistenceSession->unregisterObject($item);
return $query->execute()->getFirst();
}