首页 > 解决方案 > TCA foreign_table 如何为 select:options 选择标签

问题描述

$temporaryColumns = array(
    'my_related_item' => array(
        'label' => 'Related s',
        'l10n_mode' => 'mergeIfNotBlank',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectMultipleSideBySide',
            'items' => [
            ],
            'foreign_table' => 'tx_some_domain_model_item',
            'MM' => 'tx_some_domain_model_mm',
            'itemsProcFunc' => 'my\ext\TCA\SelectProcFunc->prepareItems',
            'enableMultiSelectFilterTextfield' => true,
            'size' => 10,
            'autoSizeMax' => 30,
            'maxitems' => 9999,
        ],
    ),
);

应该是从我想用作标签的目标实体提交的可能选项。但是在文档中找不到这个。

例如 - 默认情况下我进入选择框:选项

{value = uid
label = title }

但是我需要

{value = uid
label = clear_name}

更新:

我发现要在我无法使用的 selctbox 中获取自定义标签

'ctrl' => [
    'label' => 'clear_name',
], 

因为这将在全球范围内更改列表-但我只需要在选择框中。所以我在我的 TCA 中尝试了其他解决方案

'itemsProcFunc' => 'TBF\TbfPackage\TCA\SelectProcFunc->prepareItems',

并在 SelectProcFunc.php

namespace my\ext\TCA;
/**
 * Description of SelectProcFunc
 *
 * @author Oleg Karun
 */
class SelectProcFunc  {

    public function prepareItems(&$param) {
        debug($param);

        $newItems = [];
        foreach ($param['items'] as $item) {
            $newItem = [
                0 => $item->getUid(),
                1 => $item->getClearName()
            ];
            $newItems[] = $newItem;
        }
        //$param['items'] = $newItems;
        return $param;
    }

}

问题我的 $param['items'] 为空 - 我发现同样的问题https://forge.typo3.org/issues/85622。错误还是我做错了什么?

标签: typo3

解决方案


因为foreign_table它总是label用于呈现可用项目列表的外表。因此,如果您想要一个不同的字段,您将需要更改该选项。


推荐阅读