TCA 中自定义列的值 select

Value from custom column in TCA select

我在 Typo3 TCA 中创建了一个 select,它看起来像这样:

'company_address' => array(
  'exclude' => 1,
  'label' => 'Company Address',
  'config' => array(
    'type' => 'select',
    'foreign_table' => 'pages',
            'foreign_table_where' => ' AND doktype = 75',
            'items' => array(
                array('', 0)
            ),
    'maxitems' => 1
  )
    ),

默认值=记录的uid,如何更改?

我需要那个值 = my_column。可能吗?

您可以使用 itemProcFunc 来构建您需要的 select 选项。在您的 TCA 中,您更改配置:

'company_address' => array(
  'config' => array(
    'type' => 'select',
    'itemsProcFunc' => 'Vendor\MyExt\UserFunc\TcaProcFunc->companyAddressItems'
    'maxitems' => 1
  )
)

然后您就可以实现您的自定义功能了。我举个例子

namespace Vendor\MyExt\UserFunc;
class TcaProcFunc
{   
    /**
     * @param array $config
     * @return array
     */
    public function companyAddressItems($config)
    {
        $itemList = [];
        $rows = $this->getMySpecialDokTypeRowsFromDb();
        foreach ($rows as $row) {
            $itemList[] = ['Label of the item', $row['my_column']];
        }
        $config['items'] = $itemList;
        return $config;
    }
}

无论您在 $config['items'] 中存储什么,都将成为 select 框中的项目列表。要使这个(未经测试的)示例正常工作,您当然需要实现方法 getMySpecialDokTypeRowsFromDb()