[英]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.