在我的extbase模型中,我爲字段t3_origuid
,sys_language_uid
和l10n_parent
創建了getters和setter。堅持使用的語言字段
設置這些字段並保留時,只有l10n_parent
字段在數據庫中更新。是否可以更改其他字段,而無需手動查詢數據庫。
在我的extbase模型中,我爲字段t3_origuid
,sys_language_uid
和l10n_parent
創建了getters和setter。堅持使用的語言字段
設置這些字段並保留時,只有l10n_parent
字段在數據庫中更新。是否可以更改其他字段,而無需手動查詢數據庫。
在網絡中有一些tutorials用於將typo3的表與extbase進行映射。
本教程使用德語,但代碼僅供參考。
您已經在TCA中定義了您的字段。
'sys_language_uid' => array(
'config' => array(
'type' => 'passthrough'
)
)
與同爲其他領域...
要設置sys_language_uid
通過extbase你需要使用內部API AbstractDomainObject::_setProperty()
與$entity->_setProperty('_languageUid', $languageUid)
其中$languageUid
將是你langage記錄的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);
}
}
這非常有幫助,謝謝。您能否添加一個如何使用您的服務添加域模型對象翻譯的小例子?再次感謝! – Ole 2017-08-10 11:57:42
請不要只是鏈接的教程,但添加的代碼片段。 – lorenz 2015-05-24 22:14:02