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' => [ 
      '0' => [ 
         '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

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:

      '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',
   ],
   // [end ctrl]
   // [start columns]
   'columns' => [ 
      // [start hidden]
      'hidden' => [ 
         'exclude' => 1,
         'config' => [ 
            'type' => 'check',
            'items' => [ 
               '1' => [ 
                  '0' => 'Disable',
               ],
            ],
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end hidden]
      // [start sys_language_uid]
      'sys_language_uid' => [ 
         'exclude' => true,
         'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
         'config' => [ 
            'type' => 'language',
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end sys_language_uid]
      // [start l10n_parent]
      'l10n_parent' => [ 
         'displayCond' => 'FIELD:sys_language_uid:>:0',
         'label' => 'Translation parent',
         'config' => [ 
            'type' => 'select',
            'renderType' => 'selectSingle',
            'items' => [ 
               '0' => [ 
                  '0' => '',
                  '1' => 0,
               ],
            ],
            'foreign_table' => 'tx_styleguide_type',
            'foreign_table_where' => 'AND {#tx_styleguide_type}.{#pid}=###CURRENT_PID### AND {#tx_styleguide_type}.{#sys_language_uid} IN (-1,0)',
            'default' => 0,
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end l10n_parent]
      // [start l10n_source]
      'l10n_source' => [ 
         'exclude' => true,
         'displayCond' => 'FIELD:sys_language_uid:>:0',
         'label' => 'Translation source',
         'config' => [ 
            'type' => 'select',
            'renderType' => 'selectSingle',
            'items' => [ 
               '0' => [ 
                  '0' => '',
                  '1' => 0,
               ],
            ],
            'foreign_table' => 'tx_styleguide_type',
            'foreign_table_where' => 'AND {#tx_styleguide_type}.{#pid}=###CURRENT_PID### AND {#tx_styleguide_type}.{#uid}!=###THIS_UID###',
            'default' => 0,
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end l10n_source]
      // [start l10n_diffsource]
      'l10n_diffsource' => [ 
         'config' => [ 
            'type' => 'passthrough',
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end l10n_diffsource]
      // [start record_type]
      'record_type' => [ 
         'label' => 'type',
         'config' => [ 
            'type' => 'select',
            'renderType' => 'selectSingle',
            'items' => [ 
               '0' => [ 
                  '0' => 'type 0',
                  '1' => '0',
               ],
               '1' => [ 
                  '0' => 'Type with changed fields',
                  '1' => 'withChangedFields',
               ],
               '2' => [ 
                  '0' => 'Type with columnsOverrides',
                  '1' => 'withColumnsOverrides',
               ],
            ],
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end record_type]
      // [start input_1]
      'input_1' => [ 
         'label' => 'input_1',
         'config' => [ 
            'type' => 'input',
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end input_1]
      // [start input_2]
      'input_2' => [ 
         'label' => 'input_2, renderType=colorpicker',
         'config' => [ 
            'type' => 'input',
            'renderType' => 'colorpicker',
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end input_2]
      // [start text_1]
      'text_1' => [ 
         'exclude' => 1,
         'label' => 'text_1',
         'config' => [ 
            'type' => 'text',
         ],
      ],
      // Example from extension "styleguide", table "tx_styleguide_type"
      // [end text_1]
   ],
   // [end columns]
   // [start types]
   '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',
               ],
            ],
         ],
      ],
   ],
   // [end types]
];

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:

   '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',
               ],
            ],
         ],
      ],
   ],

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:

The record with default type `0`

The record with default type 0

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

The same record with type `withChangedFields`

The same record with type withChangedFields

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

The same record with type `withOverriddenColumns`

The same record with type withOverriddenColumns

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.