坚持语言领域

时间:2013-05-07 07:00:15

标签: typo3 extbase

在我的extbase模型中,我为字段t3_origuidsys_language_uidl10n_parent创建了getter和setter。

设置这些字段并保持不变时,只会在数据库中更新l10n_parent字段。是否可以更改其他字段,而无需手动查询数据库。

3 个答案:

答案 0 :(得分:1)

要通过extbase设置sys_language_uid,您需要将内部API AbstractDomainObject::_setProperty()$entity->_setProperty('_languageUid', $languageUid)一起使用,其中$languageUid将是您的语言记录的ID。您将在锻造中找到更完整的示例:https://forge.typo3.org/issues/61722

您也可以使用我编写的small service来轻松翻译任何域对象:

<?php
/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
 * Provides services to translate domain objects
 */
class TranslationService implements SingletonInterface {

    /**
     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
     * @inject
     */
    protected $dataMapper;

    /**
     * Translates a domain object
     *
     * @param DomainObjectInterface $origin
     * @param DomainObjectInterface $translation
     * @param int $language
     * @throws \Exception
     * @return void
     */
    public function translate(DomainObjectInterface $origin, DomainObjectInterface $translation, $language) {
        if (get_class($origin) !== get_class($translation)) {
            throw new \Exception('Origin and translation must be the same type.', 1432499926);
        }

        $dataMap = $this->dataMapper->getDataMap(get_class($origin));

        if (!$dataMap->getTranslationOriginColumnName()) {
            throw new \Exception('The type is not translatable.', 1432500079);
        }

        if ($origin === $translation) {
            throw new \Exception('Origin can\'t be translation of its own.', 1432502696);
        }

        $propertyName = GeneralUtility::underscoredToLowerCamelCase($dataMap->getTranslationOriginColumnName());

        if ($translation->_setProperty($propertyName, $origin) === FALSE) {
            $columnMap = $dataMap->getColumnMap($propertyName);
            $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_ONE);
            $columnMap->setType($dataMap->getClassName());
            $columnMap->setChildTableName($dataMap->getTableName());

            $translation->{$propertyName} = $origin;
        }

        $translation->_setProperty('_languageUid', $language);
    }
}

答案 1 :(得分:0)

您已在TCA中定义了字段。

'sys_language_uid' => array(
    'config' => array(
        'type' => 'passthrough'
    )
)

其他领域也一样......

答案 2 :(得分:-1)

在web中有一些tutorials用于映射typo3和extbase的表。

本教程是德语版,但代码不言自明。