Examples
Some examples from the conference extension to get an idea of what the field definition is capable of: a select drop-down with images, an inline relation used by two tables, and the options for translated records.
Select drop-down for records represented by images
The images of the locations below the location field of a conference
The location of a conference is a select field with a relation to the
location table and the field wizard select:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'location' => [
'label' => 'my_extension.db:conference.location',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_myextension_location',
'items' => [
['label' => '', 'value' => 0],
],
'fieldWizard' => [
'selectIcons' => [
'disabled' => false,
],
],
'relationship' => 'manyToOne',
// Venues only, not their halls
'foreign_table_where' => 'AND {#tx_myextension_location}.{#parent} = 0 ORDER BY tx_myextension_location.name',
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'location',
'',
'after:conference_date',
);
The location table names its field with the image as selicon_field:
<?php
return [
'ctrl' => [
'title' => 'my_extension.db:location',
'label' => 'name',
'label_alt' => 'city',
'label_alt_force' => true,
'selicon_field' => 'image',
'default_sortby' => 'name',
'rootLevel' => -1,
'security' => [
'ignoreRootLevelRestriction' => true,
],
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'delete' => 'deleted',
'iconfile' => 'EXT:my_extension/Resources/Public/Icons/Location.svg',
],
'columns' => [
'name' => [
'label' => 'my_extension.db:location.name',
'config' => [
'type' => 'input',
'required' => true,
],
],
'city' => [
'label' => 'my_extension.db:location.city',
'config' => [
'type' => 'input',
],
],
'image' => [
'label' => 'my_extension.db:location.image',
'config' => [
'type' => 'file',
'maxitems' => 1,
'allowed' => 'common-image-types',
'relationship' => 'manyToOne',
],
],
],
'types' => [
'0' => [
'showitem' => 'name, city, image',
],
],
];
Inline relation (IRRE) spanning multiple tables
The comments of a talk
Visitors comment on conferences and on talks. Both tables use the same
comment table: the comment stores the uid of its parent record in parent,
and the table of the parent in parent_:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'comments' => [
'label' => 'my_extension.db:talk.comments',
'config' => [
'type' => 'inline',
'foreign_table' => 'tx_myextension_comment',
'foreign_field' => 'parent',
'foreign_table_field' => 'parent_table',
'appearance' => [
'enabledControls' => [
'new' => false,
],
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'comments',
'',
'before:--div--;core.form.tabs:access',
);
Example: prefixLangTitle
On translating a record in a new language the content of the field gets
copied to the target language. It gets prefixed with
[Translate to <language name>:], here in the description of a conference:
The description of a translated conference
The language mode is defined as follows:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'description' => [
'label' => 'my_extension.db:conference.description',
'l10n_mode' => 'prefixLangTitle',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'description',
'',
'before:--div--;core.form.tabs:categories',
);
Disable the prefixLangTitle for the header field in tt_content
Use the default behaviour instead of prefix: the field will
be copied without a prepended string.
$GLOBALS['TCA']['tt_content']['columns']['header']['l10n_mode'] = '';
Select field with defaultAsReadonly
The format of a conference is the same in all languages. The field has the
option
'l10n_ set, so a translation shows
the value of the default language, which cannot be changed:
The format of a translated conference
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'event_format' => [
'label' => 'my_extension.db:conference.event_format',
'onChange' => 'reload',
'l10n_mode' => 'exclude',
'l10n_display' => 'defaultAsReadonly',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'label' => 'my_extension.db:conference.event_format.onsite',
'value' => 'onsite',
],
[
'label' => 'my_extension.db:conference.event_format.online',
'value' => 'online',
],
[
'label' => 'my_extension.db:conference.event_format.hybrid',
'value' => 'hybrid',
],
],
'default' => 'onsite',
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'event_format',
'',
'after:conference_date',
);
Translated field without l10n_display definition
The salutation of a speaker has no l10n_ definition, so it can be
changed in a translation:
The salutation of a translated speaker
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_speaker', [
'salutation' => [
'label' => 'my_extension.db:speaker.salutation',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['label' => '', 'value' => ''],
[
'label' => 'my_extension.db:speaker.salutation.mr',
'value' => 'mr',
],
[
'label' => 'my_extension.db:speaker.salutation.ms',
'value' => 'ms',
],
[
'label' => 'my_extension.db:speaker.salutation.mx',
'value' => 'mx',
],
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_speaker',
'salutation',
'',
'before:name',
);