DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

EXT: KB TCA Section

Author:Kasper Skårhøj
Created:2002-11-01T00:32:00
Changed:2006-04-25T19:13:26
Author:Bernhard Kraft
Email:kraftb@kraftb.at
Info 3:
Info 4:

EXT: KB TCA Section

Extension Key: kb_tca_section

Copyright 2000-2002, Bernhard Kraft, <kraftb@kraftb.at>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

- a GNU/GPL CMS/Framework available from www.typo3.com

Table of Contents

EXT: KB TCA Section 1

Introduction 1

What does it do? 1

Screenshots 1

Users manual 2

Creating a new section element 2

Editing a section element 2

Moving a section element around 2

Deleting a section element 3

Adminstration 3

Configuration 3

Basic setup 3

Recursion 4

Known problems 4

To-Do list 4

Sponsoring 4

Changelog 4

Introduction

What does it do?

This extension allows you to add Sections like they are known from TemplaVoila to standard TYPO3 TCA tables. Sections are a feature of TemplaVoila which allows you to add an arbitrary amount of "sub- records" into a record you created.

So it is possible for example to add a different number of Link sections to a Page-Header, where each of the link section elements contain a few fields like "Link Target", "Link Text", "Link Image".

There is no XML involved and the section elements which you can create require a real SQL table they can exist in. This of course spoils your database with an few extra tables but comes with the great advantage that you can make full-fledged SQL queries and selecting mostly all possible results directly from the database with a clever query instead of doing hundreds of simpler queries and building the final result via php-code.

There is a WIKI version of this document at:

http://think-open.org/kraftb/t3wiki/index.php/Kb_ext/EXTKBTCASection

Screenshots

img-1

[ Editing a record with a section “NNTP Message Parts” inside. Looks like Flexform-XML – Is TCA SQL Tables ]

Quick start

If you would like to get a fast working example of TCA sections just enable the “Example configuration” checkbox when installing the extension. Also create the table which gets proposed. When you have installed the extension like this the “images” field of “Text w. Images” (Also “Images” ?) will not be a “File Upload Box” anymore but rather a section which can contain an arbitraray amount of “Image,Caption,Title,Alt” sets ... But just try it.

You will get an interface like:

img-2

The FE rendering for this kind of image-storage is not set currently but this can get achieved with a few simple lines of TypoScript without the need to touch any PHP code.

If you do not want to use the example you will also not require to install the proposed table. Rather create your own section tables.

Users manual

When you create or edit a record which contains a section you will find a selctorbox inside the record which contains lines which start with “NEW abcd”. Those selectorboxes allow you to create a new related section element . (NOT IMPLEMENTED: Each of the different “NEW” options means a different kind of section element which can hold different fields. So it is possible to mix sub-records of different kind in one section. STATUS: Currently only one kind of section elments can get inserted. No mixing)

Creating a new section element

To create a new section element select one of the “NEW” options out of one of the creator-selectorboxes of a section element. If you did that you have to save the current record to let the new section elment get inserted into the database. The new element will get appended to the end of the current list or if there is a sorting criteria set for the section elements it will show up depending on the current values in the section.

Editing a section element

To edit the elements of a section just edit the fields as you would do with normal fields and afterwards press the Save button as usual. The fields should behave exactly like fields in “normal” tables and you should not notice any oddities or other unusal behaviour.

Moving a section element around

To move a section element up or down you have to mark the Up/Down checkbox next to the elments header and then press the Save button of the form. Afterwards the element should be in its new position. You should NOT (!!!) move two elements at the same time which have not at least two other elements between them. Else the sorting would get mixed up and you start to have a problem.

This behaviour will get fixed by implementing AJAX moving/delete routines. Then you also would not have to press Save for every move or delete you want to perform.

Deleting a section element

To delete a section element just mark the “Delte” checkbox next to its header and press the Save button of the Form.

Adminstration

If you set up a site using this feature you will possibly not want the editors to see the Section tables in the Web>List module. As those tables have to be fully configured TCA tables their records would show up as normals records but editing them directly would not make much sense as you will only see the fields of the single section element you are editing. So the overview gets lost.

Since TYPO3 4.0.0 there is the possiblity to hide specific tables in the Web>List module. The tables get hidden even for Admin-Users so also they can not “destroy” something by accidentally editing those section element records. This feature get's enabled via Page or User/Group Tsconfig – so you can either hide the tables completely, even for admin users, by adding the TS to the page Tsconfig of a parent of the page containing the section element records. Or you can only hide it for some specific users. The options for this is:

mod.web_list.hideTables = tx_myext_sectionTableA, tx_myext_sectionTableB

If you add it as User/Group Tsconfig you have to quit the TYPO3 backend and log in again to let the User-TSconfig of the actual session get updated.

Configuration

To get a Section inside a normal TCA table you have to modify the TCA “columns” definition usually found in the tca.php table of an extension or in the equivalent fields of the sysext extensions. You also have to add some configuration to the 'ctrl' sub-array of the table which you would like to use as section.

Basic setup

First you have to add a field definition of one field to the table which will contain the section and of course also the same field in the ext_tables.sql SQL definition file.

Section container table

An entry looks like this:

'tx_kbnntpif_messages' => Array(
  'ctrl' => ....
   .....
  'columns' => Array(
  ...
    'parts' => Array (
      'exclude' => 1,
      'label' => 'LLL:EXT:kb_nntp_if/locallang_db.php:tx_kbnntpif_messages.parts',
      'config' => Array (
        'type' => 'user',
        'userFunc' => 'EXT:kb_tca_section/class.tx_kbtcasection.php:tx_kbtcasection->getSingleField_typeSection',
        'el' => array(
          'tx_kbnntpif_message_parts' => &$GLOBALS['TCA']['tx_kbnntpif_message_parts'],
        ),
      )
    ),
   ....

And in the ext_tables.sql file a line like:

parts int(11) unsigned DEFAULT '0' NOT NULL,

This example should be mostly self explanatory. You define a “section” called “parts”. The userFunc is the magic which will render the section. In el “el” array you have to place “key => value” pairs where each “key” MUST be the name of a valid TCA table – and the value of each key should be the TCA-config (the complete one containg ctrl and else) for this table. The “&” in front of the value ensures that a reference to the TCA-config is created instead of making a copy of the configuration.

The “&” is a MUST because possibly at the time this definition gets “loaded” the “message_parts” tables TCA is not loaded completely. If you would make a copy of the array (not using the & operator) and the TCA would get completed later one then the copied array would still stay in the same uncomplete state (Because only the original gets modified) – If you create a reference using the & operator the keys point to the same array in memory and will change synchron.

Section element table

Now as this field 'parts' only contains the count of the elements contained you may ask where the relation is stored. The answer is simple: As this is a 1:n relation like the child-parent relation between pages you have to place a “parent” pointer into the child (the section elment table)

This is done by adding a field like the following:

'tx_kbnntpif_message_parts' => Array(
  'ctrl' => ....
   .....
  'columns' => Array(
  ...
    'msgparent' => Array (
      'exclude' => 1,
      'label' => 'LLL:EXT:kb_nntp_if/locallang_db.php:tx_kbnntpif_message_parts.msgparent',
      'config' => Array (
        'type' => 'group',
        'internal_type' => 'db',
        'allowed' => 'tx_kbnntpif_messages',
        'show_thumbs' => '1',
        'size' => 1,
        'maxitems' => 1,
        'minitems' => 1,
      )
    ),

Into the table which will get used as section elements. You do not need to add the field to the “types” or “palette” configuration. When you do not add it an editor will not be able to “move” a section element from one main-record to another (Assign a section element to another record).

Please take care that the field has “maxitems” set to 1. Else it would be possible to place more than one relation inside and this is of course not working (Also pages can only have one parent).

You need to configure the field in the ext_tables.sql file like:

msgparent int(11) unsigned DEFAULT '0' NOT NULL,

The last step is to add the following configuration to the 'ctrl' sub- array of the section-elemnt table:

$TCA['tx_kbnntpif_message_parts'] = Array (
  'ctrl' => Array (
    ...
    'sectionParentField' => 'msgparent',
    ...

This is a rather simple configuration which enables the section to get displayed inside the container records. In the example with the NNTP messages I wanted to display “message_parts” inside “messages” and also “message_parts” inside “message_parts” (the recursion). To solve this you can also configure the 'ctrl' section like this:

$TCA['tx_kbnntpif_message_parts'] = Array (
  'ctrl' => Array (
    ...
    'sectionParentField' =>
      'tx_kbnntpif_messages' => 'msgparent',
      'tx_kbnntpif_message_parts' => 'partparent',
    ),
    'sectionAddWhere' => array(
      'tx_kbnntpif_messages' => ' AND partparent=0',
    ),
    ...

The “sectionParentField” property changed to an array and contains now 2 entries telling which one the parent-field field is depending on which record get's rendered actually. So when “message_parts” get rendered inside “messages” the “msgparent” field is considered as parent. But when “message_parts” get rendered inside “message_parts” again the “partparent” field is taken as valid parent field. This is required because you can not (should not) mix references to two different tables in the same field – else you can't do proper (fast) queries to fetch the elements. (I consider speed in the backend also as important – at least my customers do that :)

Another feature added in the above ext_tables.php code is the “sectionAddWhere” clause. You can use it to restrict the records which get selected as elements. In our case we only want to display elements in the “messages” table which are not a child of another “message_part” (have partparent set to 0).

If the later example seems too complicated rather start your tests without recursion and different parent tables – this will ease things a lot.

About the example

The above example is about a NNTP (Newsserver) interface for TYPO3. What you see is the “parts” field of the messages tables which contains all the MIME parts of a single NNTP/SMTP MIME message. As you probably know a MIME message (which are both NNTP and normal SMTP- Mails aka. E-mails) consits only of a header and a message mody. The body again can (but must not) consist of multiple parts encapsulated in a so called multipart-MIME message .

In this case I choose that the message parts – which can be simple plain texts or files – get embedded into the message as TCA section. If a mail only consists of a plain-text part only one element will get added. But if a message contains a text and 2 files for example then 3 parts will get created and listed below each other.

In the ext_tables.sql file you will have to add a line like:

parts int(11) unsigned DEFAULT '0' NOT NULL,

to satisfy TYPO3 which requires a real SQL table field for each configured TCA field. The field will hold the number of referenced elements like it is known from TYPO3 n:m tables (why are they called “ *m:m* ” in TYPO3 ???)

Recursion

What I not told before is that a MIME message-part may again be of the type “multipart-MIME message” so one of the parts can again contain multiple subparts :) . If you already had a lot to do with trees you will surely notice that this kind of structure is equivalent to a tree.

As I already told a message part can be “text” or “file” (message type). This difference in the apperance of the record is achieved via a “TCA Type” field for the message_parts table which decides which fields shall get displayed depended on the message type set.

To cope with the required recursion I added a message type “container” which when selected will only show one field: “A section field”. This section field will then hold the sub-MIME parts of a single MIME-part. The TCA defintion for this looks like:

'tx_kbnntpif_message_parts' => Array(
  'ctrl' => ....
   .....
  'columns' => Array(
  ...
    'subparts' => Array (
      'exclude' => 1,
      'label' => 'LLL:EXT:kb_nntp_if/locallang_db.php:tx_kbnntpif_message_parts.subparts',
      'displayCond' => 'FIELD:parttype:=:3',
      'config' => Array (
        'type' => 'user',
        'userFunc' => 'EXT:kb_tca_section/class.tx_kbtcasection.php:tx_kbtcasection->getSingleField_typeSection',
        'el' => array(
          'tx_kbnntpif_message_parts' => &$GLOBALS['TCA']['tx_kbnntpif_message_parts'], // Recursive section for subparts. Nice isn't it.
        ),
      )
    ),

You will surely notice that this time the value of the only key in “el” points to “message_parts” again. But the field “subparts” resided in the “message_parts” table itself – so here we created a recursion. You can add an arbitrary amount of elements down to any depth :)

Known problems

Currently it does not work to add elements of different type (tables) to one section – This is possible with TemplaVoila but in the case of TCA sections it becomes a huge problem that the different tables can have different fields. So you can't (or just hard) execute one query which returns all elements from the used tables in correct order. You would either have to do sorting in PHP or find another solution (One already hangs around in my brain :)

To-Do list

Add support for mixed tables.

Sponsoring

Money is rare in todays world – so if your company is happy to have enough of it and you find this (my) extensions useful feel free to transfer an amount which suits your taste to “ kraftb@kraftb.at ” via PayPal. Thanks for your support.

If you are a one-man freelancer show like me and have to keep track of finance yourself please do not send me your last bit of money ! I would feel bad accepting money from someone who pherhaps has even less than me. So this call is only directed to companies who are suited well enough. You can also add the sponsored money to your expenses for taxes cause I will properly pay income-taxes for the received money. So it would again be no clever idea to sponsor money for which you already paid those taxes.

Companies which have sponsored money can get listed on my website including or excluding the amount of sponsored money completely as they like.

Changelog

Version :

Version

Version :

Date

Date :

Changelog

Changelog :

0.0.0

Version

0.0.0

Date

2006-04-24 19:00 CET

Changelog

Initial release

0.0.1

Version

0.0.1

Date

2006-04-25 19:15 CET

Changelog

Updated documentation. (“msgparent” part was missing) and added a configuration example for tt_content “images” field.

{Changelog}

img-3 EXT: KB TCA Section - 6