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

get TYPO3 Extbase Repository items in other languages

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

我测试了什么:

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

我用 "matching" 和 "statement" 尝试过,但结果查询使用活动语言或在 (0,-1) = (default/all).

看来这是 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" 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 一个简单的 CustomQueryResult class:

class CustomQueryResult extends \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult {

    /**
     * @var \YOURVENDOR\YOUREXT\Persistence\Storage\CustomDataMapper
     * @inject
     */
    protected $dataMapper;
}

3.Implement CustomDataMapper class 并覆盖方法 "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;
    }
}