本文介绍了获取其他语言的TYPO3 Extbase存储库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从extbase存储库中以其他语言获取项目?

How can i get items from an extbase respository in a different language?

我测试过的东西

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

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

But the result is always the parent (lang) object.

我用匹配"和语句"进行了尝试,但结果查询使用了活动语言或在(0,-1)=(默认/全部)中搜索sys_language_id.

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).

推荐答案

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

It seems that this is a bug in extbase which will not removed until TYPO3 7.1:https://forge.typo3.org/issues/45873

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

For me this solves the problem: https://forge.typo3.org/issues/45873#note-27

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

After this modification it is possible to get translated objects from the repository (e.g byUid or in a own query)

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

(Copied from the linked page, 07.04.2015)

扩展中的1.HACK extbase(在ext_localconf.php中)以注册"CustomQueryResult"类:

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.实现一个简单的CustomQueryResult类:

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.实现CustomDataMapper类并覆盖方法"mapSingleRow":

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

这篇关于获取其他语言的TYPO3 Extbase存储库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:58