Record types

type
Path

$GLOBALS['TCA'][$table]['ctrl']

type

string (field name)

Scope

Display / Proc.

Field name, which defines the "record type".

The value of this field determines which one of the types configurations are used for displaying the fields in the FormEngine. It will probably also affect how the record is used in the context where it belongs.

The most widely known usage of this feature is the case of Content Elements where the Type: selector is defined as the "CType" field and when you change that selector you will also get another rendering of the form:

The type selector of a content elements

It is used for example by the "doktype" field in the "pages" table.

On changing the value of the field defined in type the user gets prompted to reload the record.

Only one type field can be defined. If you need to reload the record on changing another field, see property onchange.

It is also possible to make the type depend on the value of a related record, for example to switch using the type field of a foreign table. The syntax is relation_field:foreign_type_field. For example the sys_file_metadata table takes its type from the sys_file table.

Examples

the type stored in a field

The table tx_styleguide_type table from the "examples" extension defines different types. The field used for differentiating the types is the "record_type" field. Hence we have the following in the ['ctrl'] section of the tx_examples_dummy table:

EXT:styleguide/Configuration/TCA/tx_styleguide_type.php
[
    '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',
    ],
]
Copied!

The "record_type" field can take values ranging from 0 to 2. Accordingly we define types for the same values. Each type defines which fields will be displayed in the BE form:

EXT:styleguide/Configuration/TCA/tx_styleguide_type.php
[
    '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',
                    ],
                ],
            ],
        ],
    ],
]
Copied!

See the section about types for more details.

Type in relation to a foreign table's field

The type of the record is fetched from the record specified in field `foreign_table`

The following table tx_styleguide_type_foreign stores its relation to the table tx_styleguide_type in the field foreign_table.

The type of the table tx_styleguide_type_foreign comes from the content of the field tx_styleguide_type:record_type of the related field.

The type is therefore defined via type = 'foreign_table:record_type'.

The control section of the table tx_styleguide_type_foreign looks like this:

EXT:styleguide/Configuration/TCA/tx_styleguide_typeforeign.php
[
    'ctrl' => [
        'title' => 'Form engine - type from foreign table',
        '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' => 'foreign_table:record_type',
    ],
]
Copied!

The field foreign_table in the same table is a normal singleSelect field. It can be any kind of 1 - 1 or 1 - n relation.

EXT:styleguide/Configuration/TCA/tx_styleguide_typeforeign.php
[
    'columns' => [
        'foreign_table' => [
            'label' => 'type from foreign table',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'foreign_table' => 'tx_styleguide_type',
                'minitems' => 1,
                'maxitems' => 1,
                'size' => 1,
            ],
        ],
    ],
]
Copied!