【问题标题】:Typo3, TCA forms view depending on the chosen optionTypo3,TCA 根据所选选项形成视图
【发布时间】:2012-04-04 01:43:21
【问题描述】:

我在后端制作了一个 TCA 表单,根据选择字段“类型”中的值会发生什么变化:

这个选择字段基本上包含选项:

  • 转文本
  • 网址
  • 图片

I can make the system working so, that when "rte text" is chosen, it shows specified fields for "rte text", when url is chosen it shows specified fields for "url" etc..

在我的例子中,内容总是保存在“内容”字段的数据库中,而选定的类型保存在“类型”字段中。

我的问题是我还没有找到根据所选类型更改“内容”表单字段/配置的方法。

例如,当我选择“rte text”时,它应该为内容字段使用这种配置(富文本编辑器):

'content' => array (        
        'exclude' => 0,     
        'label' => 'Content',       
        'config' => array (
            'type' => 'text',
            'cols' => '30',
            'rows' => '5',
            'wizards' => array(
                '_PADDING' => 2,
                'RTE' => array(
                    'notNewRecords' => 1,
                    'RTEonly'       => 1,
                    'type'          => 'script',
                    'title'         => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
                    'icon'          => 'wizard_rte2.gif',
                    'script'        => 'wizard_rte.php',
                ),
            ),
        )
    ),

当我选择“图片”时,它应该为内容字段使用这种配置(文件上传器):

'content' => array (        
        'exclude' => 0,     
        'label' => 'Content',       
        'config' => array (
            'type' => 'group',
            'internal_type' => 'file',
            'allowed' => '',    
            'disallowed' => 'php,php3', 
            'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'], 
            'uploadfolder' => 'uploads/tx_uploadshere',
            'size' => 1,    
            'minitems' => 0,
            'maxitems' => 1,
        )
    ),

有没有办法根据选择框中的值更改该配置。我试图将两个内容放在一个数组中,但没有按照这种方式工作。

【问题讨论】:

  • 可以通过额外的一点 PHP 来实现您想要的,但我认为在一个表字段中混合不同的内容是不正确的。我认为@konsolenfreddy 建议的方法会更好。

标签: typo3 typo3-tca


【解决方案1】:

很遗憾,您无法通过type 更改单个字段的属性。

但是,您可以影响正在显示的内容。所以可以配置两个独立的字段并切换显示:

ext_tables.php

$TCA['tx_yourextension_yourtable'] = array(
    'ctrl' => array(
        //...
        'type'=>'type',
        //...
    ),
);

TCA.php

$TCA['tx_yourextension_yourtable'] = array(
    'ctrl' => $TCA['tx_yourextension_yourtable']['ctrl'],
    'types' => array(
        0 => array('showitem' => 'content_rte'),
        1 => array('showitem' => 'content_image'),
    ),
    'columns' => array(
        'content_rte' => array(
            'exclude' => 0,
            'label' => 'Content',
            'config' => array(
                'type' => 'text',
                'cols' => '30',
                'rows' => '5',
                'wizards' => array(
                    '_PADDING' => 2,
                    'RTE' => array(
                        'notNewRecords' => 1,
                        'RTEonly' => 1,
                        'type' => 'script',
                        'title' => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
                        'icon' => 'wizard_rte2.gif',
                        'script' => 'wizard_rte.php',
                    ),
                ),
            )
        ),
        'content_upload' => array(
            'exclude' => 0,
            'label' => 'Content',
            'config' => array(
                'type' => 'group',
                'internal_type' => 'file',
                'allowed' => '',
                'disallowed' => 'php,php3',
                'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
                'uploadfolder' => 'uploads/tx_uploadshere',
                'size' => 1,
                'minitems' => 0,
                'maxitems' => 1,
            )
        ),
    ),
    // ...
);

(注意:为简单起见,我删除了 hiddensys_language_uid 等系统字段)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    相关资源
    最近更新 更多