在我的TCA中我有关系n:1 SuperClass - > Code
'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”字段。我可以做吗?
在文档中,“简单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,
],
],
我很确定,这对于选择是不可能的,但它可以用于内联元素。在那里你可以使用字段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;
}