How to quickly create custom content elements in TYPO3 6.x
Asked Answered
S

2

11

In TYPO3 6.x, what is an easy way to quickly create custom content elements?

A typical example (Maybe for a collection of testimonials):

In the backend (with adequate labels):

  • An image
  • An input field
  • A textarea

When rendering:

  • Image resized to xy
  • input wrapped in h2
  • textarea passed through parseFunc and wrapped in more markup

Ideally, these would be available in the page module as cType, but at least in the list module. And use fluid templates.

My questions:

  • From another CMS I am used to content item templates being applied to the BE and the FE at the same time (you write the template for what it should do, and then there's a backend item just for that type of content element) - but that's not how fluid works - or can it be done?

  • Is there an extension that would handle such custom content elements (other than Templavoila)?

  • Or do I have to create a custom extbase/fluid extension for each such field type?

  • And, by the way: is there a recommendable tutorial for the new extbase kickstarter? I got scared away by all that domain modelling stuff.

Senarmontite answered 27/8, 2013 at 11:39 Comment(0)
S
24

That scaring domain modeling stuff is probably best option for you :)

Create an extension with FE plugin which holds and displays data as you want, so you can place it as a "Insert plugin". It's possible to add this plugin as a custom CType and I will find a sample for you, but little bit later.

Note, you don't need to create additional models as you can store required data ie. in FlexForm.

From FE plugin to CType

Let's consider that you have an extension with key hello which contains News controller with list and single actions in it.

In your ext_tables.php you have registered a FE plugin:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin($_EXTKEY, 'News', 'Scared Hello News');

When it's working fine you can add it to the list of content types (available in TCA) just by adding fifth param to the configurePlugin method in your ext_localconf.php:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'TYPO3.' . $_EXTKEY,
    'News',
    array('News' => 'list, show'),
    array('News' => ''),
    \TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT // <- this one
);

Next part (basing on this site) is adding your plugin to the New Content Element Wizard as noticed in TYPO3 Wiki since TYPO3 ver. 6.0.0 changed a little, so easiest way is adding something like this into your ext_tables.php:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:hello/Configuration/TypoScript/pageTsConfig.ts">');

and in /typo3conf/ext/hello/Configuration/TypoScript/pageTsConfig.ts file write add this:

mod.wizards.newContentElement.wizardItems.plugins.elements.tx_hello_news {
    icon = gfx/c_wiz/regular_text.gif
    title = Scared Hello News
    description = Displays Scared News
    tt_content_defValues.CType = hello_news
}

# Below the same for TemplaVoila
templavoila.wizards.newContentElement.wizardItems.plugins.elements.tx_hello_news {
    icon = gfx/c_wiz/regular_text.gif
    title = Scared Hello News
    description = Displays Scared News
    tt_content_defValues.CType = hello_news
}

Note that proper key tx_hello_news should be combination of lowercased tx_, $_EXTKEY and plugin name - used in registerPlugin method.

You can stop here if you are bored ;)

Bring tt_content's fields back into your CType

Above steps will cause that no typical fields will be available in the TCA for your element, so you need to copy something or create own. To see how it works just see some sample, in the backend in left menu choose ADMIN TOOLS > Configuration > TCA > tt_content > types

There you'll find all types in the system, choose the most required and copy its [showitem] node into your own. Again in ext_tables.php add this PHP array:

$TCA['tt_content']['types']['hello_news']['showitem'] = $TCA['tt_content']['types']['textpic']['showitem'];

Again: hello_news is combination of lowercased $_EXTKEY and FE plugin name...

Of course if it's required you can compose quite own set of fields, one by one by custom string:

$TCA['tt_content']['types']['hello_news']['showitem'] = '--palette--;LLL:EXT:cms/locallang_ttc.xml:palette.general;general, --palette--;LLL:EXT:cms/locallang_ttc.xml:palette.header;header';

Access the fields in Extbase Controller:

Fortunately is easiest part as you can just access it as an Array:

$currentTtContent = $this->configurationManager->getContentObject()->data;
$header = $currentTtContent['header'];
debug($currentTtContent);
debug($header);
Sepulchral answered 27/8, 2013 at 11:46 Comment(5)
Cool, I already got de-scared by this great introduction (in german) from Mittwald: mittwald.de/fileadmin/downloads/pdf/dokus/…Senarmontite
I created a very simple list extension (only list view) already, it's definitely faster than the old kickstarter. I'm very interested in the custom CType example.Senarmontite
WOW - thanks a lot - this will take some time to process - fantastic :-)Senarmontite
Hi @Sepulchral it DID take some time to try this out. I can create the plugin and add it to the wizard. But I haven't understood what is meant by "Bring tt_content's fields back into your CType" yet. I thought this would somehow bring the fields I defined for the extension's items (which can be edited via list view) back to the tt_content area, which is what I am looking for. But your solution does something different, or am I wrong?Senarmontite
To update this thread: also check out the walkthrough by Daniel on usetypo3.com/custom-fsc-element.htmlSenarmontite
S
4

I think http://typo3.org/extensions/repository/view/dce will do exactly what I was looking for

Senarmontite answered 10/10, 2015 at 11:25 Comment(1)
DCE content will not be reusable throughout the site in the way that I'm looking for it. typo3.org/extensions/repository/view/mask is the more flexible competitor – adding or reusing database fields you can query with TypoScript or otherwise afterwardsSenarmontite

© 2022 - 2024 — McMap. All rights reserved.