Examples

Required type - minimal configuration

The type 0 is required to be defined. It has to have at least the property showitem defined. A minimal configuration can be seen here, for example:

'types' => [
    [
        'showitem' => 'title',
    ],
]

It displays nothing but a single field.

Required type - tabs and palettes

The following configuration specifies two tabs: the first one labelled “general” with three fields “category” “subject” and “message”, and the second one labelled “access” with the field “personal”. Only the default type “0” is specified. Opening such a record looks like this:

A common example of the control section

Optional additional types

The power of the “types” configuration becomes clear when you want the form composition of a record to depend on a value from the record. Let’s look at the tx_styleguide_type table from the styleguide extension. The ctrl section of its TCA contains a property called :php: type:

'ctrl' => [
    'title' => 'Form engine - type',
    'label' => 'input_1',
    'tstamp' => 'tstamp',
    'crdate' => 'crdate',
    'cruser_id' => 'cruser_id',
    'delete' => 'deleted',
    'sortby' => 'sorting',
    'iconfile' => 'EXT:styleguide/Resources/Public/Icons/tx_styleguide.svg',
    'versioningWS' => true,
    'origUid' => 't3_origuid',
    'languageField' => 'sys_language_uid',
    'transOrigPointerField' => 'l10n_parent',
    'transOrigDiffSourceField' => 'l10n_diffsource',
    'translationSource' => 'l10n_source',
    'enablecolumns' => [
        'disabled' => 'hidden',
    ],
    'type' => 'record_type',
]

This indicates that the field called record\_type is to specify the type of any given record of the table. Let’s look at how this field is defined in the property columns:

'columns' => [
    'record_type' => [
        'label' => 'type',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectSingle',
            'items' => [
                [
                    'type 0',
                    '0',
                ],
                [
                    'Type with changed fields',
                    'withChangedFields',
                ],
                [
                    'Type with columnsOverrides',
                    'withColumnsOverrides',
                ],
            ],
        ],
    ],
]

There’s nothing unusual here. It’s a pretty straightforward select field, with three options. Finally, in the types section, we define what fields should appear and in what order for every value of the type field:

'types' => [
    0 => [
        'showitem' => 'record_type, input_1, text_1',
    ],
    'withChangedFields' => [
        'showitem' => 'record_type, input_1, input_2, text_1',
    ],
    'withColumnsOverrides' => [
        'showitem' => 'record_type, input_1, input_2, text_1',
        'columnsOverrides' => [
            'input_2' => [
                'label' => 'input_2, readOnly, size=10, empty renderType',
                'config' => [
                    'renderType' => '',
                    'readOnly' => true,
                    'size' => 10,
                ],
            ],
            'text_1' => [
                'config' => [
                    'renderType' => 't3editor',
                    'format' => 'html',
                ],
            ],
        ],
    ],
]

The result if the following display when type 0 is chosen:

../_images/CtrlType0.png

Changing to type withChangedFields reloads the form and displays the a different set of fields:

../_images/CtrlTypeWithChangedFields.png

And finally, type withOverriddenColumns shows the fields and overrides part of the configuration of the fields:

../_images/CtrlTypeWithOverriddenColumns.png

Note

It is a good idea to give all “types” speaking names, except the default type 0. Therefore we named the other types withChangedFields and withOverriddenColumns instead of 1, 2 etc. In a real life example they should have names from the domain.