3
votes

I made an extbase Extension for custom content elements. Since this is my first extension I started with a simple "hello_world_ce". This are my files:

ext_tables.php

<?php
$TCA['tt_content']['types']['hello_world_ce']['showitem'] = '--palette--;LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.general;general, --palette--;LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.header;header';

ext_localconf.php

<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:'.$_EXTKEY.'/Configuration/TypoScript/ModWizards.ts">');

ModWizards.ts

mod.wizards {
    newContentElement {
        wizardItems {
            hello_world {
                header = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_tab_header
                elements {
                    hello_world_ce {
                        icon = gfx/c_wiz/regular_header.gif
                        title = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world
                        description = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.description
                        tt_content_defValues {
                            CType = hello_world_ce
                        }
                    }
                }
            }
            show = *
        }
    }
}

In the TYPO3 Backend I see my content element and can add it to a page but the dropdown menu for the content type says INVALID VALUE ("hello_world_ce")

What am I missing?

EDIT: I found the missing part. I needed to add my content type to the CType array

ext_tables.php

$backupCTypeItems = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'];
$GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] = array(
    array(
        'LLL:EXT:'.$_EXTKEY.'/Resources/Private/Language/locallang_mod.xlf:content_tab_header',
        '--div--'
    ),
    array(
        'LLL:EXT:'.$_EXTKEY.'/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world',
        'hello_world_ce',
        'i/tt_content_header.gif'
    )
);
foreach($backupCTypeItems as $key => $value){
    $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'][] = $value;
}
1

1 Answers

1
votes

The question was edited, but I think there is a better way to achieve the solution.

Only to be clear about the problem:

The content element hello_world_ce was not added to the "types" dropdown by adding a new content element.

The hint in the question is correct it was not defined for the CType field. But instead of manipulating the array you could use a core function:

 // Adds the content element to the "Type" dropdown
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
   array(
      'LLL:EXT:your_extension_key/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world',
      'hello_world_ce',
      'i/tt_content_header.gif'
   ),
   'CType',
   'your_extension_key'
);

Here is a very good example of how to add your own content element in the version TYPO3 7.6.

Note: This function is accessible in TYPO3 6.2 as well.