get TYPO3 Extbase Repository items in other languages

ε祈祈猫儿з 提交于 2019-12-01 21:49:58

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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!