[TYPO3-v4] Simple Content Element API
Jeff Segars
jsegars at alumni.rice.edu
Mon Mar 22 15:23:38 CET 2010
Hey guys,
I wanted to run an idea by you that has been bouncing around in my head
for several months to see if there's any interest for inclusion in 4.4.
Apologies in advance for the length of the post :)
The basic idea is to add some very simple way to create new content
elements that can be shared among TYPO3 installations as extensions. The
scope is very similar to FCEs with the difference being that they do not
require TemplaVoila, are quicker to create (no mapping) and are much
more easily shared and updated (extensions instead of T3Ds).
For PHP developers, this offers a more rapid way to add custom contenet
when a full extension would be overkill. This also opens up some doors
for site builders who are not PHP developers. If they know Typoscript
and FlexForm XML, they can add new content elements.
As far as technical details go, this ends up being a pairing of
Flexforms for backend data entry and nothing but TypoScript for frontend
output.
We've already made an initial attempt at doing this sort of thing in the
WEC Content Elements extension [1] so I'll attempt to describe what we
did there. It's nothing earth shattering at all, but the non-developers
who have see it really like it.
1. Add a simple PHP API for telling TYPO3 about the new content element
(Something like this could easily live in t3lib_extMgm)
=======================================================================
tx_weccontentelements_lib::addContentElement($_EXTKEY, 'youtube') adds
the necessary entries to the TCA and New Content Element Wizard.
Locallang paths, icons, and flexform paths can all be defined but
there's a simple convention that should work 95% of the time.
tx_weccontentelements_lib::addTyposcript($_EXTKEY, 'youtube') adds the
TypoScript needed for frontend output. This TS is very similar to what
the built in content elements use. As a quick example, see [2] which
embeds YouTube on a page.
2. Add ability to read FlexForm data from TypoScript via getData (This
could be an enhancement to tslib_cObj)
=======================================================================
If we're writing extensions that are simply FlexForm XML and TypoScript,
then we need a bridge between the two. Many people have done this before
and its really pretty simple with the hooks for getData already. Perhaps
its time to bring this into the core.
The syntax for our implementation looks something like this:
t3datastructure : pi_flexform->width
You can see more details at [2]
3. Add ability to loop over FlexForm sections (This could be an
enhancement to tslib_cObj)
=======================================================================
Once we can read simple values from FlexForms, the next obvious step is
to operate on sections. This is useful for something like a slideshow
content element that contains multiple images.
An example of our implementation is in line 139 and following at [3]. We
have new FFSECTION cObject that is responsible for iterating over
sections and it requires a rootPath to iterate over. Within that,
getData is extended with a new flexformSection keyword that reads
FlexForm values relative to the root path.
4. Add ability to insert header data from a content element (This could
be a pageRenderer enhancement)
=======================================================================
Since many of these content elements will be widgets implementing
Javascript functionality, it only makes sense to have some way that they
can add header data to the page but only when the content element is
actually in use.
In wec_contentelements we've added a HEADERDATA cObject that is an idea
Olly had prior to the pageRenderer. A better solution would enhancing
the pageRenderer somehow.
Wrap Up
=======================================================================
Wait, you actually read this far? :) In our experience, it takes about
15 minutes to create a simple content element extension such as YouTube.
This means we can react to client needs quickly and give them a better
editing experience inside TYPO3. Like I said initially, the ideas and
code aren't anything revolutionary but I think pulling them all together
takes many of the good concepts from FCEs one step further.
Any thoughts? Is this something anyone would be interested in seeing
for 4.4?
Thanks for reading along...
Jeff
[1] http://typo3.org/extensions/repository/view/wec_contentelements/current/
[2]
http://svn.webempoweredchurch.org/projects/contentelements/repository/entry/trunk/wec_contentelements/youtube/content.ts
[3]
http://svn.webempoweredchurch.org/projects/contentelements/repository/entry/trunk/wec_contentelements/slideshow/content.ts#L139
More information about the TYPO3-project-v4
mailing list