【问题标题】:How to extend common content elements of TYPO3 with FlexForm through TCA overwrite?如何通过 TCA 覆盖扩展 TYPO3 的常用内容元素与 FlexForm?
【发布时间】:2019-04-27 12:18:25
【问题描述】:

我想用一个字段扩展 TYPO3 的一些内容元素以输入自定义 CSS 类。因此,我认为 pi_flexform 字段是一个好去处,因为它提供了以后添加更多值的灵活性。 (不,我不想为所有 CSS 类创建 Layout-Options)

在 TCA 覆盖中 - 例如“texpic” - 我添加了以下结构:

$GLOBALS['TCA']['tt_content']['types']['textpic'] = array_replace_recursive(
  $GLOBALS['TCA']['tt_content']['types']['textpic'], [
    'columns' => [
      'pi_flexform' => [
        'l10n_display' => 'hideDiff',
        'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:pi_flexform',
        'config' => [
          'type' => 'flex',
          'ds_pointerField' => 'list_type,CType',
          'ds' => [
            'default' => '
              <T3DataStructure>
                <ROOT>
                  <type>array</type>
                  <el>
                    <customClass>
                      <TCEforms type="array">
                        <label>My custom CSS classes</label>
                        <config type="array">
                          <type>input</type>
                          <eval>trim</eval>
                        </config>
                      </TCEforms>
                    </customClass>
                  </el>
                </ROOT>
              </T3DataStructure>
            '
          ],
          'search' => [
            'andWhere' => '{#CType}=\'list\''
          ]
        ]
      ]
    ],
    'showitem' => '
      --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
      --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
      --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.header;header_minimal,
      pi_flexform,
      [...]
  ']
);

pi_flexform 字段显示在后端,但我上面的 XML 配置没有被评估。它显示Plugin Options [pi_flexform] The Title:,这是来自文件typo3\sysext\frontend\Configuration\TCA\tt_content.php 的演示示例值。所以看来我的代码没有被完全覆盖,只有“showitem”部分有效。这可能是什么问题?

编辑 1: 发完问题后发现自己的错误:列的定义需要直接进入tt_content部分:

$GLOBALS['TCA']['tt_content']['columns']['pi_flexform'] = [...]

不幸的是,这意味着它将对所有 tt_content 元素产生影响,除了其他插件会再次覆盖它。所以问题仍然存在:有没有一种简单的方法来扩展默认内容元素,而无需编写自己的扩展名或添加数据库字段?

【问题讨论】:

    标签: typo3 flexform


    【解决方案1】:

    找到了一个简单的解决方案!只需将 FlexForm XML 直接添加到 addPiFlexFormValue() 并将内容元素指定为第三个参数:

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
        '*',
        '<T3DataStructure>
      <ROOT>
      <type>array</type>
        <el>
          <customClass>
            <TCEforms type="array">
              <label>My custom CSS classes</label>
              <config type="array">
                <type>input</type>
                <eval>trim</eval>
              </config>
            </TCEforms>
          </customClass>
        </el>
      </ROOT>
    </T3DataStructure>',
        'textpic'
    );
    

    它是如此的连贯:浪费了数小时的尝试,而在发布问题后突然解决方案就自动出现了。

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 2016-05-06
      • 1970-01-01
      • 2021-01-22
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多