[TYPO3-mvc] Re: Get translated record fails

David H david.herber at vacuubrand.com
Wed Nov 22 11:09:16 CET 2017


This works for me:



// controller
// do not forget to use following stuff in the controllers top section
// use TYPO3\CMS\Core\Utility\GeneralUtility;
// use TYPO3\CMS\Extbase\Object\ObjectManager;
// use TYPO3\CMS\Extbase\Persistence\Generic\Session;

$langArr = array(0=>'de', 1=>'en', 2=>'fr', 3=>'es', 4=>'ru');
foreach($langArr as $langId=>$langKey){
$checkProdExists = $this->productRepository->findByUid($prodId, $langId);
$checkProdExists->getFirst()->setTitle($checkProdExists->getFirst()->setTitle('Title '.$langKey))
$this->productRepository->update($checkProdExists->getFirst());

// now comes the important part, as this motherf. keeps getting the record-data in the context of the default language otherwise
// important: the uid of the returned record always stays the uid of the default language because this is how typo3 loves to go down at the party. everything is made in relation to the records default language uid. but the context will change in the desired language so the data that is updated after that will be updated in the specific language.

$this->persistenceManager->persistAll();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$persistenceSession = $objectManager->get(Session::class);
$persistenceSession->destroy();
// now the current object session gets destroyed an the upcoming $this->productRepository->findByUid 's work fine.
}

// repository
public function findByUid($uid, $langId = 0) {
		$query = $this->createQuery();
		$query->getQuerySettings()->setRespectStoragePage(false);
		$query->getQuerySettings()->setLanguageUid($langId);
		$query->matching($query->equals('uid',$uid));
		$entries=$query->execute();
		
		return $entries;
    }


More information about the TYPO3-project-typo3v4mvc mailing list