简体   繁体   中英

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

I want to extend some content-elements of TYPO3 with a field to enter a custom CSS class. Therefore I thought, the pi_flexform field is the place to go as it gives the flexibility also to add more values later. (No, I don't want to create Layout-Options for all the CSS classes)

In a TCA overwrite for - lets say "texpic" for example - I added the following structure:

$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,
      [...]
  ']
);

The pi_flexform field is displayed in the backend, but my XML configuration from above is not evaluated. It shows Plugin Options [pi_flexform] The Title: which is the demo example value from the file typo3\\sysext\\frontend\\Configuration\\TCA\\tt_content.php . So it seems my code is not entirely overwritten, only the section "showitem" works. What could be the issue here?

EDIT 1: After I posted the question, I found my mistake: the definition for columns needs to go directly into the tt_content section:

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

Unfortunately this means that it will have an effect for ALL tt_content elements, except other plugins will overwrite this again. So the question remains: is there a simple way to extend default content-elements, without writing an own extension nor adding database-fields?

Found an easy solution! Just add the FlexForm XML directly to addPiFlexFormValue() and specify the content-element as 3rd parameter:

\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'
);

Its so wired: wasting hours of trying out, and suddenly after posting the question the solution comes just by itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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