2

在我的 extbase 模型中,我为字段t3_origuidsys_language_uidl10n_parent.

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

4

3 回答 3

1

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

您还可以使用我编写的这个小服务来轻松翻译任何域对象:

<?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);
    }
}
于 2015-05-23T21:01:02.000 回答
0

您已经在 TCA 中定义了您的字段。

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

其他领域也是如此……

于 2014-05-20T15:17:05.837 回答
-1

网上有一些教程用于将typo3的表与extbase进行映射。

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

于 2013-06-03T08:27:33.063 回答