blog.Resource

Archive:

News-Feeds:


RSS 2.0
RSS 0.91
RDF
ATOM 0.3
July 14, 2009

Integrating own Content Elements

Category: Steffen Kamper, Core

A tutorial on how to integrate and render own Content Element in TYPO3

As i didn't found any tutorial for this purpose i want to show you how to create own Content Elements with own rendering, which are integrated in TYPO3 as the others like text, images, form etc.

So lets start: create your base extension (i call it "myownce" in this tutorial) with kickstarter just as an empty skeleton.

manually add these files if not present:

static/constants.txt
static/setup.txt
ext_localconf.php
ext_tables.php
class.tx_cobj_myownce.php

Now let's start

Step1 (setup.txt):

define tt_content.myownce:

tt_content.myownce= COA
tt_content.myownce {
    10 = < lib.stdheader

    20 = MYOWNCE
    20 { ... }
}



Step 2 (ext_tables.php) :

define TCA CType (the content type, in our case "myownce" )

$TCA['tt_content']['columns']['CType']['config']['myownce'] = array(
    'label' => 'LLL:EXT:....',
    'config' => array(...)
);

Step 3 (ext_tables.php):

Do you need a flexform for the configuration? Than add the following:

$TCA['tt_content']['columns']['pi_flexform']['config']['ds'][',myownce'] = t3lib_div::getURL(t3lib_extMgm::extPath($_EXTKEY) . 'flexform.xml');


Step 4 (ext_tables.php):

add it to CTypes:
$TCA['tt_content']['columns']['CType']['config']['items'][] = array('LLL:EXT:myownce/locallang.xml:tt_content.CType_myownce', 'myownce', 'EXT:myownce/ext_icon.gif');

define showitem (in this case with flexform)
$TCA['tt_content']['types']['myownce'] = array(
    'showitem' => 'CType;;4;;1-1-1, hidden, header;;3;;2-2-2, linkToTop;;;;3-3-3,
                    --div--;LLL:EXT:myownce/locallang.xml:CType.myownce, pi_flexform;;;;3-3-3,
                    --div--;LLL:EXT:cms/locallang_tca.xml:pages.tabs.access, starttime, endtime'
);

Step 5 (ext_localconf.php)

Define the CE for NewContentElementWizard

t3lib_extMgm::addPageTSConfig('
mod.wizards.newContentElement.wizardItems {
    myownce {
        icon = ...
    }
    special.show := addToList(myownce)
}

Have a look to typo3/sysext/cms/ext_localconf.php how it's done.


Step 6 (ext_localconf.php)

register the Hook
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClassDefault']['media'] = 'EXT:myownce/class.tx_cobj_myownce.php:tx_cObj_myOwnCE';

Step 7 (class.tx_cobj_myownce.php):

Now write your class with own rendering
require_once(PATH_tslib . 'interfaces/interface.tslib_content_cobjgetsinglehook.php');

class tx_cObj_myOwnCE implements tslib_content_cObjGetSingleHook {
    protected $cObj;


    public function getSingleContentObject($contentObjectName, array $configuration, $TypoScriptKey, tslib_cObj &$parentObject) {
        $this->cObj =& $parentObject;
        switch($contentObjectName) {
            case 'MYOWNCE':
                return $this->MYOWNCE($configuration);
            break;
        }
    }

    /**
     * Rendering the cObject, MYOWNCE
     *
     * @param    array        Array of TypoScript properties
     * @return    string        Output
     */
    function MYOWNCE($conf) {
        $content = '';   
         // it is a TS object
        $str = $this->cObj->stdWrap($conf['str'], $conf['str.']);
        if ($conf['thisIsAnyVariable']) {
           $content = $str;
        }
        return $content;
    }
}

you can write in Typoscript whatever you want, you'll find it in the conf array. This is just a dummy example also to show how to use stdWrap.

The NewContentElementWizard is new since version 4.3, so this method will only work from version 4.3+

Have fun, i expect to see some new Content Elements in future :)


If you get any problems, i uploaded a demo extension here.


comments

comment #1
Gravatar: Patrick Patrick July 14, 2009 18:21
Great reading ! Thanks for sharing.

comment #2
Gravatar: Pim Broens Pim Broens July 20, 2009 09:12
A clear and quick lesson on this issue. Great work, thanks!

Sorry, comments are closed for this post.