Record types
See also
The Field types (config > type) are a concept different from the record types.
The types
section is mandatory for all table definitions.
Basic tables with only one type use this section to define which fields should
be displayed in the backend form in the property showitem
.
If the table should provide multiple record types, the field containing the type
must be defined in
$GLOBALS['TCA'][$table]['ctrl']['type']
and all supported types must be array entries in $GLOBALS
.
Each entry in the types
array is an array with at least the property showitem
defined.
Defining multiple types in one table is similar to what is often done with Single Table Inheritance in Object-orientated programming.
Table of Contents
Subpages
Changed in version 13.3
Creating content elements has been simplified by removing the need to define the system fields for each element again and again. This shrinks down a content element's showitem to just the element specific fields. See also Automatically added system fields to content types (tt_content).
A basic table without distinct types
When the table record does not support multiple types it still needs to define one type in order to define which fields should be displayed in the backend form for the default type.
For example the comment of a blog post can be stored in a table that supports no additional types:
<?php
return [
'ctrl' => [
'title' => 'Comment',
// ...
],
'types' => [
'0' => [
'showitem' => 'hidden, name, email, content, date',
],
],
'columns' => [
// ...
],
];
Omitting the types
section is not supported by TYPO3.
Supporting multiple record types in the same table
When a table supports multiple record types, the type of a record must be
saved in a dedicated column, commonly named record_
or just type
.
Commonly a select field is used for that purpose.
The name of this table is registered in the ctrl
section via property
type.
For example a blog post might have one of several types where the fields displayed in the backend differ
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:blog_example/.../locallang_db.xlf:post_title',
'label' => 'title',
'type' => 'record_type',
'typeicon_classes' => [
'0' => 'tx-blog-post',
'link' => 'tx-blog-post-link',
'special' => 'tx-blog-post-special',
],
// ...
],
'types' => [
'0' => [
'showitem' => 'blog, title, date, author, content, comments, ',
],
'link' => [
'showitem' => ' blog, title, date, author, link, ',
],
'special' => [
'showitem' => 'blog, title, date, author, content, tags, comments, ',
],
],
'columns' => [
'record_type' => [
'label' => 'LLL:EXT:blog_example/.../post_types',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'label' => 'Blog Post',
'value' => '0',
],
[
'label' => 'Link to External Blog Post',
'value' => 'link',
],
[
'label' => 'Special Blog Post',
'value' => 'special',
],
],
'default' => '0',
],
],
// ...
],
];
For each record type you can define additional creationOptions and change field display definitions via columnsOverrides.
It is also possible to define distinct previewRenderers.
You can also define individual icons per type, using property ctrl -> typeicon_classes.
Properties of types
section of TCA
Name | Type | Scope |
---|---|---|
array (columns fields overrides) | Display | |
list of options | ||
bool | ||
array | ||
string | Display | |
string (list of field configuration sets) |
columnsOverrides
-
- Type
- array (columns fields overrides)
- Path
- $GLOBALS['TCA'][$table]['types'][$type]
- Scope
- Display
- Examples
- Examples for columnsOverrides
Changed or added ['columns'] field display definitions.
This allows to change the column definition of a field if a record of this type is edited. Currently, it only affects the display of form fields, but not the data handling.
A typical property that can be changed here is
render
.Type The core uses this property to override for instance the "bodytext" field config of table "tt_content": If a record of type "text" is edited, it adds "enableRichtext = 1" to trigger an RTE to the default "bodytext" configuration, and if a type "table" is edited, it adds "renderType = textTable" and "wrap = off" to "bodytext".
The FormEngine basically merges "columnsOverrides" over the default "columns" field after the record type has been determined.
Attention
It is not possible to override any properties in "Proc." scope: The DataHandler does not take "columnsOverrides" into account. Only pure "Display" related properties can be overridden. This especially means that columns config 'type' must not be set to a different value.
Deprecated since version 12.4
Setting the TCA option allowLanguageSynchronization for a specific column in a record type via
columns
is not supported.Overrides
creationOptions
-
- Type
- list of options
- Path
- $GLOBALS['TCA'][$table]['types'][$type]['creationOptions']
New in version 13.0
The page TSconfig option newContentElement.wizardItems.[group].elements.[name] can be defined through TCA as well:
saveAndClose
-
- Type
- bool
- Default
- false
- Path
- $GLOBALS['TCA'][$table]['types'][$type]['creationOptions']['saveAndClose']
- Examples
- Example: Create the blog plugin at once
New in version 13.0
If true, clicking on the new element wizard will take the user directly to the page module, rather than showing the edit form from the form engine.
Can be overridden with page TSconfig option saveAndClose.
defaultValues
-
- Type
- array
- Path
- $GLOBALS['TCA'][$table]['types'][$type]['creationOptions']['defaultValues']
- Examples
- Example: Create the blog plugin at once
New in version 13.0
Default values inserted into the fields of the
tt_
record on creation via the "New Content Element" wizardcontent Can be overridden with page TSconfig option tt_content_defValues.
previewRenderer
-
- Type
- string
- Path
- $GLOBALS['TCA'][$table]['types'][$type]['previewRenderer']
- Scope
- Display
- Examples
types-
example- preview Renderer
To configure a preview renderer for the whole table see previewRenderer.
Configures a backend preview for a content element.
Have also a look at Configure custom backend preview for content element for more details.
Use property previewRenderer of section ctrl to configure the preview globally for the whole table.
showitem
-
- Type
- string (list of field configuration sets)
- Path
- $GLOBALS['TCA'][$table]['types'][$type]['showitem']
- Required
- true
- Examples
- Display all fields on one page of the form
Configuration of the displayed order of fields in FormEngine and their tab alignment.
The whole string is a comma
,
separated list of tokens. Each token can have keywords separated by semicolon;
.Each comma separated token is one of the following:
field
Name;field Label - Name of a field to show. Optionally an alternative label (string or LLL reference) to override the default label from columns section.
--
palette--;palette Label;palette Name -
Name of a palette to show. The label (string or LLL reference) is optional. If set, it is shown above the single palette fields. The palette name is required and must reference a palette from the palette section.
--palette--;;caching // Show palette "caching" without additional label --palette--;Caching;caching // Show palette "caching" with label "Caching"
Copied! --
div--;tab Label - Put all fields after this token onto a new tab and name the tab as given in "tabLabel" (string or LLL reference).
Note
It is good practice to add a comma in excess behind the very last field name as shown in the examples above. The FormEngine code will ignore this, but it helps developers to not forget about a comma when additional fields are added, which can suppress an annoying "Why is my new field not displayed?" bug hunt.
Extensions can also modify
showitem
values by utilizingExtension
. See Customization Examples for details.Management Utility:: add To All TCAtypes ()
Changed in version 13.0
The properties bitmask_
and bitmask_
been removed, it is not considered anymore when rendering
records in the backend record editing interface.
In case, extensions still use this setting, they should switch to casual
$GLOBALS
fields instead, which
can be powered by columns based on string values.
Extended examples for using the types
section of TCA
Display all fields on one page of the form
The table containing the blog comments does not contain many fields. So they can all be displayed on one page of the backend form without using tabs:
Group fields using tabs and use palettes
If a table has a larger number of fields, grouping them into tabs and palettes can improves the backend user experience. Palettes have the additional value that they can be reused across different record types.
<?php
return [
'types' => [
'0' => [
'showitem' => '
record_type, blog, title, date, author, content,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
hidden,
--palette--;;paletteStartStop,
fe_group,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,
--palette--;;paletteLanguage,
',
],
],
'palettes' => [
'paletteStartStop' => [
'showitem' => 'starttime, endtime',
],
'paletteLanguage' => [
'showitem' => 'sys_language_uid, l10n_parent',
],
],
];
The syntax for tabs is:
--
Where label can be a string or an LLL reference (preferred).
The syntax to insert a palette is:
--
The label can be omitted.
See also
Examples for columnsOverrides in type section of TCA
Demonstrates property: columnsOverrides.
For example the special blog post type might require the author to be set and use a different render type and description for the content:
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:blog_example/.../locallang_db.xlf:post_title',
// ...
],
'types' => [
'special' => [
'columnsOverrides' => [
'author' => [
'config' => [
'required' => true,
],
],
'content' => [
'description' => 'You can use Markdown syntax for the content. ',
'config' => [
'renderType' => 'codeEditor',
],
],
],
'showitem' => 'blog, title, date, author, content, tags, comments, ',
],
// ...
],
// ...
];
While the field type type
cannot be changed in the columns
the
render type render
can be changed.
Override default values by type
A blog post of type link should have a different default value for the author field then other blog post types:
PreviewRenderer examples
Demonstrates property: previewRenderer.
This specifies the preview renderer only for records with the c
blogexample_
as determined by the field Ctype
of the table tt_
.
This could be used to preview the blog plugin in the page module.
$GLOBALS['TCA']['tt_content']['types']['blogexample_list']['previewRenderer']
= \MyVendor\MyExtension\Preview\PreviewRenderer::class;
Example: Create the blog plugin at once
Demonstrates property: saveAndClose.
When editors create a new blog plugin in the plugin is automatically saved and the user returned to the page module:
<?php
$GLOBALS['TCA']['tt_content']['types']['blogexample_list']['creationOptions']['saveAndClose'] = true;
Note
This property only takes effect in the table tt_
.