gpt4 book ai didi

typo3 - 获取其他语言的 TYPO3 Extbase Repository 项目

转载 作者:行者123 更新时间:2023-12-02 03:27:47 25 4
gpt4 key购买 nike

我如何从 extbase 存储库中获取不同语言的项目?

我测试了什么:

  • findByUid($childUid)
  • $query->getQuerySettings()->setRespectSysLanguage(FALSE);
  • $query->getQuerySettings()->setSysLanguageUid(3);

但结果始终是父(lang)对象。

我尝试使用“匹配”和“声明”,但结果查询使用事件语言或在 (0,-1) = (default/all) 中搜索 sys_language_id。

最佳答案

这似乎是 extbase 中的一个错误,直到 TYPO3 7.1 才会被删除: https://forge.typo3.org/issues/45873

对我来说,这解决了问题:https://forge.typo3.org/issues/45873#note-27

此修改后,可以从存储库中获取翻译后的对象(例如通过 Uid 或在自己的查询中)

(从链接页面复制,2015 年 4 月 7 日)


1.HACK extbase 在你的扩展中(在你的 ext_localconf.php 中)注册一个“CustomQueryResult”类:

// 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;
}
}

关于typo3 - 获取其他语言的 TYPO3 Extbase Repository 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29395809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com