You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3新增内容cType时FlexForm配置问题:表单归属与列表标题

问题1:将FlexForm表单移出"Plugin Options"分组

在TYPO3 v7/v8中,FlexForm默认归到"Plugin Options"分组,要么是因为内容类型基于list(插件类型),要么是默认TCA配置把pi_flexform放在了该分组下。要自定义分组,只需调整tt_content的TCA types配置,把pi_flexform放到你想要的分组里即可。

场景A:自定义独立内容类型(推荐)

如果是新增独立的CType(而非基于现有list类型),直接配置该类型的showitem结构:

// Configuration/TCA/Overrides/tt_content.php

// 1. 注册自定义内容类型
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
    'tt_content',
    'CType',
    [
        'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tt_content.CType.custom_content',
        'custom_content',
        'icon-identifier-for-your-content'
    ],
    'text',
    'after'
);

// 2. 配置该内容类型的显示字段,将FlexForm放在自定义分组
$GLOBALS['TCA']['tt_content']['types']['custom_content'] = [
    'showitem' => '
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
            --palette--;;general,
            header, header_layout, header_position,
        --div--;LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tabs.custom_options, // 自定义分组
            pi_flexform,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
            --palette--;;hidden,
            --palette--;;access,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes,
            rowDescription,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended,
    ',
];

// 3. 关联FlexForm配置文件
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
    'custom_content', // 仅对该内容类型生效
    'FILE:EXT:your_ext/Configuration/FlexForms/CustomContent.xml'
);

场景B:基于现有插件类型(list CType)

如果你的内容是插件(CType=list + 自定义list_type),需要覆盖默认的showitem,替换分组名称:

// Configuration/TCA/Overrides/tt_content.php

// 关联FlexForm到你的list_type
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
    '*',
    'FILE:EXT:your_ext/Configuration/FlexForms/MyPlugin.xml',
    'your_ext_myplugin' // 你的list_type标识
);

// 替换Plugin Options分组为自定义分组
$GLOBALS['TCA']['tt_content']['types']['list']['showitem'] = str_replace(
    '--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:plugin, pi_flexform',
    '--div--;LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tabs.plugin_options, pi_flexform',
    $GLOBALS['TCA']['tt_content']['types']['list']['showitem']
);

问题2:解决列表视图显示[notitle]的问题

列表显示[notitle]通常是因为tt_content.header字段为空,或者内容类型没有提供标题输入入口,又或者标题存在于FlexForm但没被列表视图识别。

方案1:使用默认header字段(最简单)

确保你的内容类型showitem中包含header字段,让用户可以输入标题:

在前面的showitem配置中已经包含了header, header_layout, header_position,用户输入标题后,列表视图会自动读取header字段的值,不再显示[notitle]。

方案2:从FlexForm中提取标题(如果标题存在于FlexForm)

如果标题存储在FlexForm的某个字段中(比如settings.title),需要自定义标签函数来提取该值:

  1. 首先在TCA中配置标签函数:
// Configuration/TCA/Overrides/tt_content.php
$GLOBALS['TCA']['tt_content']['ctrl']['label_userFunc'] = \YourVendor\YourExt\Utility\ContentLabelUtility::class . '::getCustomTitle';
  1. 创建标签处理类:
<?php
namespace YourVendor\YourExt\Utility;

use TYPO3\CMS\Core\Utility\XmlUtility;

class ContentLabelUtility
{
    public function getCustomTitle(&$params, $pObj)
    {
        $row = $params['row'];
        
        // 仅处理你的自定义内容类型
        if ($row['CType'] === 'custom_content' || $row['list_type'] === 'your_ext_myplugin') {
            // 解析FlexForm数据
            if (!empty($row['pi_flexform'])) {
                $flexData = XmlUtility::convertFlexFormContentToArray($row['pi_flexform']);
                // 从FlexForm中获取标题(根据你的FlexForm结构调整路径)
                $flexTitle = $flexData['settings']['title'] ?? '';
                if (!empty($flexTitle)) {
                    $params['title'] = $flexTitle;
                    return;
                }
            }
            //  fallback到默认header字段
            $params['title'] = !empty($row['header']) ? $row['header'] : '[no title]';
        } else {
            // 其他内容类型使用默认标签逻辑
            $params['title'] = $pObj->defaultLabel($params);
        }
    }
}

这样列表视图会优先显示FlexForm中的标题,没有的话再用header字段的值,避免显示[notitle]。


内容的提问来源于stack exchange,提问作者Peon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 09:08:33