In my TCA I have relation 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,
],
],
Field "super_class" related to field "uid". I need to set relation between "super_class" and "code" fields, not "uid" field. Can I do it?
Right in the docs, section "Simple 1:n relation". https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Type/Inline.html
You're looking for the config option 'foreign_table_field', which defines the relation field in the foreign table. This should do the trick for you:
'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,
],
],
I'm really sure, that this isn't possible for selects, but it's possible for inline elements. There you can use the field foreign_table_field. Otherwise you could use a user function for that:
'config' => [
'type' => 'user',
'userFunc' => YYY\XXX\TCA\TcaReferenceField::class . '->render',
]
The code would be something like this:
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.