繁体   English   中英

如何使用 FlexForm 通过 TCA 覆盖扩展 TYPO3 的常见内容元素?

[英]How to extend common content elements of TYPO3 with FlexForm through TCA overwrite?

我想用一个字段来扩展 TYPO3 的一些内容元素以输入自定义 CSS 类。 因此,我认为 pi_flexform 字段是可以去的地方,因为它提供了稍后添加更多值的灵活性。 (不,我不想为所有 CSS 类创建布局选项)

在 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 元素产生影响,除非其他插件会再次覆盖它。 所以问题仍然存在:是否有一种简单的方法来扩展默认的内容元素,而无需编写自己的扩展或添加数据库字段?

找到了一个简单的解决方案! 只需将 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'
);

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM