How can i get items from an extbase respository in a different language?
What i tested:
findByUid($childUid)
$query->getQuerySettings()->setRespectSysLanguage(FALSE);
$query->getQuerySettings()->setSysLanguageUid(3);
But the result is always the parent (lang) object.
I tried it with "matching" and with "statement" but the result query uses the active language or searches for sys_language_id in (0,-1) = (default/all).
It seems that this is a bug in extbase which will not removed until TYPO3 7.1: https://forge.typo3.org/issues/45873
For me this solves the problem: https://forge.typo3.org/issues/45873#note-27
After this modification it is possible to get translated objects from the repository (e.g byUid or in a own query)
(Copied from the linked page, 07.04.2015)
1.HACK extbase in your extension (in your ext_localconf.php) to register a "CustomQueryResult" class:
// The code below is NO PUBLIC API!
/** @var $extbaseObjectContainer \TYPO3\CMS\Extbase\Object\Container\Container */
$extbaseObjectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
$extbaseObjectContainer->registerImplementation('TYPO3\CMS\Extbase\Persistence\QueryResultInterface', 'YOURVENDOR\YOUREXT\Persistence\Storage\CustomQueryResult');
unset($extbaseObjectContainer);
2.Implement a simple CustomQueryResult class:
class CustomQueryResult extends \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult {
/**
* @var \YOURVENDOR\YOUREXT\Persistence\Storage\CustomDataMapper
* @inject
*/
protected $dataMapper;
}
3.Implement the CustomDataMapper class and overwrite the method "mapSingleRow":
class CustomDataMapper extends \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper {
/**
* Maps a single row on an object of the given class
*
* @param string $className The name of the target class
* @param array $row A single array with field_name => value pairs
* @return object An object of the given class
*/
protected function mapSingleRow($className, array $row) {
$uid = isset($row['_LOCALIZED_UID']) ? $row['_LOCALIZED_UID'] : $row['uid'];
if ($this->identityMap->hasIdentifier($uid, $className)) {
$object = $this->identityMap->getObjectByIdentifier($uid, $className);
} else {
$object = $this->createEmptyObject($className);
$this->identityMap->registerObject($object, $uid);
$this->thawProperties($object, $row);
$object->_memorizeCleanState();
$this->persistenceSession->registerReconstitutedEntity($object);
}
return $object;
}
}
来源:https://stackoverflow.com/questions/29395809/get-typo3-extbase-repository-items-in-other-languages