在我的TCA中我有关系n:1 SuperClass - >代码
'super_class' => [
'exclude' => true,
'label' => 'Super Class',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_classification_item',
'minitems' => 0,
'maxitems' => 1,
],
],
字段“super_class”与字段“uid”相关。我需要设置“super_class”和“code”字段之间的关系,而不是“uid”字段。我可以做吗?
答案 0 :(得分:1)
在文档中,“简单1:n关系”部分。 https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Type/Inline.html
您正在寻找配置选项'foreign_table_field',它定义了外表中的关系字段。这应该适合你:
'super_class' => [
'exclude' => true,
'label' => 'Super Class',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_classification_item',
'foreign_table_field' => 'code',
'minitems' => 0,
'maxitems' => 1,
],
],
答案 1 :(得分:-1)
我非常确定,这对于选择来说是不可能的,但对于内联元素来说这是可能的。在那里你可以使用字段foreign_table_field。否则你可以使用用户函数:
'config' => [
'type' => 'user',
'userFunc' => YYY\XXX\TCA\TcaReferenceField::class . '->render',
]
代码将是这样的:
public function render(array $configuration, UserElement $userElement) {
$row = $configuration['row'];
// Do some Magic here.
$select = '<label style="font-weight: 400;">' . self::MESSAGE_FIELD_LABEL;
$select .= '<select name="' . $configuration['itemFormElName'] . '" class="form-control form-control-adapt" ' .
'onchange=\'' . $configuration['fieldChangeFunc']['alert'] . '\'>';
$select .= '<option value=""></option>';
foreach ($contentElementUids as $siteName => $contentElementUid) {
$isSelected = ($contentElementUid === (int) $configuration['itemFormElValue']);
$select .= '<option ' . ($isSelected ? 'selected' : '') . ' value="' . $contentElementUid . '">' .
$siteName . '</option>';
}
$select .= '</select></label>';
return $select;
}