TYPO3: How to configure $GLOBALS['TCA']['tt_content']['types']

1.5k views Asked by At

I have an extension with a content element. I want to display it in the content element wizard. For this, I created tt_content.php. The code in it looks like this:

$GLOBALS['TCA']['tt_content']['types']['extensionkey_contentelementname'] = array(
    'types' => [
        '0' => [
            'showitem' => '
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, category, subject, message,
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, personal
        ',
        ],
    ]
);

(I obviously replaced extensionkey_contentelementname with the real name)

This throws me an error when trying to create the content element:

No or invalid showitem definition in TCA table tt_content for type extensionkey_contentelementname

What did I do wrong?

2

There are 2 answers

0
Julian Hofmann On BEST ANSWER

You are adding two array levels too much. You are already in $GLOBALS['TCA']['tt_content']['types'], so the typesand 0 is not needed anymore.

https://docs.typo3.org/typo3cms/extensions/fluid_styled_content/7.6/AddingYourOwnContentElements/Index.html#configuration-tca-overrides-tt-content-php

0
Timon On

In Configuration/TCA/Overrides/tt_content.php:

$GLOBALS['TCA']['tt_content']['types']['extensionkey_contentelementname'] = [
    'showitem' => '
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, category, subject, message,
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, personal
        ',
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
    'tt_content',
    'CType',
     [
         'My content element',
         'extensionkey_contentelementname',
         'content-image',
     ],
     'textmedia',
     'after'
 );

You got a duplicate 'types' there.

Use this in page TS config to have it in the content element wizard.

$GLOBALS['TCA']['tt_content']['types']['extensionkey_contentelementname'] = [
    'showitem' => '
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, category, subject, message,
            --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, personal
        ',
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
    'tt_content',
    'CType',
     [
         'My content element',
         'extensionkey_contentelementname',
         'content-image',
     ],
     'textmedia',
     'after'
 );