Reputation: 1410
I created an extbase model and try to set the sys_language_uid field when creating a new item. For some reason though, it is completely ignored and always set to 0, even when the value I try to enter is definitely 1.
My Model looks like this:
class Ad extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* sysLanguageUid
*
* @var integer
*/
protected $sysLanguageUid;
/**
* @return int
*/
public function getSysLanguageUid()
{
return $this->sysLanguageUid;
}
/**
* @param int $sysLanguageUid
*/
public function setSysLanguageUid($sysLanguageUid)
{
$this->sysLanguageUid = $sysLanguageUid;
}
// ... etc.
}
and in my controller all I try to do is this:
$ad = new Ad();
$ad->setSysLanguageUid($GLOBALS['TSFE']->sys_language_uid);
$ad->setSomeOtherParam('xxx');
$this->adRepository->add($ad);
The other param is saved just fine. sys_language_uid exists in ext_tables.sql and in the TCA:
'columns' => array(
'sys_language_uid' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.language',
'config' => array(
'type' => 'select',
'foreign_table' => 'sys_language',
'foreign_table_where' => 'ORDER BY sys_language.title',
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
),
),
),
'some_other_field' => ....
)
Why is setSysLanguageUid not working? Any hints?
Upvotes: 2
Views: 2562
Reputation: 1313
Actually all that you need is a getter and a setter since you enherit the protected $_languageUid;
property from \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
that it self enherits it from TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject
/**
* @return int
*/
public function getSysLanguageUid(): int
{
return $this->_languageUid;
}
/**
* @param int $sysLanguageUid
* @return Ad
*/
public function setSysLanguageUid(int $sysLanguageUid)
{
$this->_languageUid = $sysLanguageUid;
return $this;
}
You could also do it without any change to your model since TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject
gives you a getter _getProperty()
// With your custom getters and setters
$ad->getSysLanguageUid()
// With the getter from AbstractDomainObject
$ad->_getProperty('_languageUid')
Upvotes: 1
Reputation: 736
From 2021 and TYPO3 10.x
/**
* @var int
*/
protected $sysLanguageUid;
/**
* Get sys language
*
* @return int
*/
public function getSysLanguageUid()
{
return $this->_languageUid;
}
/**
* Set sys language
*
* @param int $sysLanguageUid language uid
*/
public function setSysLanguageUid($sysLanguageUid)
{
$this->_languageUid = $sysLanguageUid;
}
Upvotes: 0
Reputation: 1410
it seems like setSysLanguageUid doesn't work because typo3 is UNNECESSARILY CONVOLUTED AND DIFFICULT. For some reason it is possible to set the language ID but only by defining and using these getters and setters:
/**
* _languageUid
* @var int
*/
protected $_languageUid;
/**
* @param int $_languageUid
* @return void
*/
public function set_languageUid($_languageUid) {
$this->_languageUid = $_languageUid;
}
/**
* @return int
*/
public function get_languageUid() {
return $this->_languageUid;
}
I swear, typo3 is gonna give me a heart attack one of these days....
Upvotes: 10