【问题标题】:TYPO3 - changing own Field on edit page by custom content elementTYPO3 - 通过自定义内容元素在编辑页面上更改自己的字段
【发布时间】:2021-11-22 09:42:58
【问题描述】:

我使用 TYPO3 版本创建了一个自定义内容元素。 10.4.21,但是我有问题。

问题:在内容元素的每个编辑页面上显示相同的字段。

我只想在我的自定义内容元素上使用自己的字段(对于我的翻转框内容元素)。但是如果我选择例如一个普通的文本元素,那么我也可以通过文本元素在编辑页面上看到我自己的字段。

代码我写在TCA/Overrides/tt_content.php:

###############################################
#                    Front side               #
###############################################
// front side header
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    [
       'tx_pagesaddfields_frontsideheader' => [
          'exclude' => 0,
          'label' => 'Front side header',
          'config' => [
             'type' => 'text',
             'renderType' => 'input',
             'items' => [
                [
                   0 => '',
                   1 => ''
                ]
             ],
          ],
       ],
    ]
 ); 
 
 // front side bodytext
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    [
       'tx_pagesaddfields_frontsidebodytext' => [
          'label' => 'Front side bodytext',
          'config' => [
                'type' => 'text',
                'cols' => 40,
                'rows' => 15,
                'enableRichtext' => true,
          ],
       ],
    ]
 );
 
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
    'tt_content',
    'general',
    'tx_pagesaddfields_frontsideheader, tx_pagesaddfields_frontsidebodytext',
    'after:tx_container_parent'
 ); 
 
 
 ###############################################
 #                Back side                    #
 ###############################################
 
 // back side header
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    [
       'tx_pagesaddfields_backsideheader' => [
          'exclude' => 0,
          'label' => 'Back side header',
          'config' => [
             'type' => 'text',
             'renderType' => 'input',
             'items' => [
                [
                   0 => '',
                   1 => ''
                ]
             ],
          ],
       ],
    ]
 );
 
 // back side bodytext
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    [
       'tx_pagesaddfields_backsidebodytext' => [
          'label' => 'Back side bodytext',
          'config' => [
                'type' => 'text',
                'cols' => 40,
                'rows' => 15,
                'enableRichtext' => true,
          ],
       ],
    ]
 );
 
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
    'tt_content',
    'general',
    'tx_pagesaddfields_backsideheader, tx_pagesaddfields_backsidebodytext',
    'after:tx_pagesaddfields_frontsidebodytext'
 ); 

我知道是因为我写了“addTCAcolumns('tt_content')。但我不知道如何重写它们以仅在我的自定义编辑页面上显示我的新字段。

它是正确的页面吗? https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ExtensionArchitecture/ExtendingTca/Examples/Index.html (通过 exanple1)和 https://docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Type/User/Index.html#columns-user?

我尝试这样做,但它在我的网站上不起作用。不幸的是,我没有足够的PHP经验......如果你知道其他网站或者你可以在这里解释,请在这里写下来。

我希望任何人都可以帮助我。谢谢。

【问题讨论】:

  • 请将其分成多个帖子,每个帖子一个问题。我会在这里回答你的第一个问题。

标签: php typo3


【解决方案1】:

最佳做法是为每个自定义内容元素添加一个文件到TCA/Overrides/。名称由您决定,TYPO3 会读取此文件夹中的所有.php 文件。 content_element_<your_ctype>.phptt_content_<your_ctype>.php 经常用作名称。

https://github.com/benjaminkott/bootstrap_package/blob/master/Configuration/TCA/Overrides/203_content_element_card_group.php

在这里,您可以看到 CType 为 card_group 的自定义内容元素在 bootstrap_package 中是如何完成的

在第 42 行 $GLOBALS['TCA']['tt_content']['types']['card_group'] 中,配置被限制为 ['(C)type']['card_group']'showitem' => ' 告诉 TYPO3 为该内容元素显示什么以及如何显示字段。

从第 70 行开始,您可以看到如何设置新字段,在第 49 行,您可以看到它是如何添加的。

【讨论】:

    猜你喜欢
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    相关资源
    最近更新 更多