如何从另一种语言的extbase存储库中获取项目?
我测试了什么:
findByUid($childUid)
$query->getQuerySettings()->setRespectSysLanguage(FALSE);
$query->getQuerySettings()->setSysLanguageUid(3);
但结果始终是父(lang)对象。
我试过"匹配"和"陈述"但结果查询使用活动语言或在(0,-1)=(默认/全部)中搜索sys_language_id。
答案 0 :(得分:1)
似乎这是extbase中的一个错误,直到TYPO3 7.1才会删除: https://forge.typo3.org/issues/45873
对我而言,这解决了问题:https://forge.typo3.org/issues/45873#note-27
在此修改之后,可以从存储库中获取翻译的对象(例如,通过使用或在自己的查询中)
(从链接页面复制,2015年4月7日)
1.Hack extbase在你的扩展中(在你的ext_localconf.php中)注册一个" 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.实现一个简单的CustomQueryResult类:
class CustomQueryResult extends \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult {
/**
* @var \YOURVENDOR\YOUREXT\Persistence\Storage\CustomDataMapper
* @inject
*/
protected $dataMapper;
}
3.实现CustomDataMapper类并覆盖方法" 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;
}
}