Php 设置TYPO3的自定义图标直接从数据库选择选项

Php 设置TYPO3的自定义图标直接从数据库选择选项,php,typo3,typo3-8.x,Php,Typo3,Typo3 8.x,我已经为带有TCA设置的DB输入创建了一个表单 其中一个是选择字段,我需要为每个选项使用不同的图标。这些图标名称(核心图标)存储在db field Icon(可更改)中: 可轻松加载主要数据: 'issuer_id' => [ 'exclude' => true, 'label' => 'LLL:EXT:lu_nas/Resources/Private/Language/locallang_db.xlf:document.status', 'conf

我已经为带有TCA设置的DB输入创建了一个表单

其中一个是选择字段,我需要为每个选项使用不同的图标。这些图标名称(核心图标)存储在db field Icon(可更改)中:

可轻松加载主要数据:

'issuer_id' => [
    'exclude' => true,
    'label'   => 'LLL:EXT:lu_nas/Resources/Private/Language/locallang_db.xlf:document.status',
    'config'  => [
        'type'                => 'select',
        'eval'                => 'required',
        'minitems'            => 0,
        'maxitems'            => 1,
        'foreign_table'       => 'tx_lunas_domain_model_status',
        'foreign_table_where' => 'ORDER BY tx_lunas_domain_model_status.title ASC',
        'items'               => [['', '',]],
    ],
],
其中,TCA
tx\u lunas\u domain\u model\u status.php
settings
ctrl
设置为使用title
'label'=>'title'
作为名称

我知道我也可以添加
'iconfile'=>“EXT:lu\u nas/Resources/Public/Icons/Status.svg”
作为所有条目的默认图标,但我不需要它(每个条目需要不同)

到目前为止,我还发现我可以添加带有图标的自定义项,如下所示:

'items' => [
    ['', ''],
    ['Limited access', 5, 'overlay-locked'],
    ['Inactive', 3, 'overlay-info'],
    ['Old', 2, 'overlay-readonly'],
    ['Active', 1, 'overlay-approved'],
],

但是我如何知道图标名保存在哪个DB列中,以便我可以直接从数据库加载这些数据呢?

我很确定,目前在TYPO3中不能这样做,但可以使用userFunction。在那里,您可以为图标添加类

'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;
}
公共函数呈现(数组$configuration,UserElement$UserElement){
$row=$configuration['row'];
//在这里施点魔法。
$select=''.self::消息\字段\标签;
$select.='';
$select.='';
foreach($contentElementUids作为$siteName=>$contentElementUid){
$isSelected=($contentElementUid==(int)$configuration['itemFormElValue']);
$select.=''。
$siteName.';
}
$select.='';
返回$select;
}

谢谢,我们将对此进行测试。但听起来还是很奇怪,如果有一个选项
iconfile
title
可以定义值,为什么没有像
iconfield
这样的选项,或者只有
icon
可以用值定义db字段:/耶,这是一个很好的缺失功能。:)
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;
}