Color
New in version 13.0
When using the color type, TYPO3 takes care of
generating the according database field.
A developer does not need to define this field in an extension's
ext_tables.sql file.
New in version 13.0
Color palettes have been added.
The TCA type color can be used to render a JavaScript-based color picker.
The according database field is generated automatically.
Color palettes can be defined via page TSconfig. This way, for example, colors defined in a corporate design can be selected with one click.
Table of contents:
Example: Define a simple color picker in TCA
The color of a conference:
The color of a conference
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'color' => [
'label' => 'my_extension.db:conference.color',
'config' => [
'type' => 'color',
'valuePicker' => [
'items' => [
['label' => 'my_extension.db:conference.color.orange', 'value' => '#ff8700'],
['label' => 'my_extension.db:conference.color.teal', 'value' => '#2f99a4'],
['label' => 'my_extension.db:conference.color.night', 'value' => '#292545'],
],
],
'behaviour' => [
'allowLanguageSynchronization' => true,
],
'searchable' => false,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'color',
'',
'before:--div--;core.form.tabs:categories',
);
Properties of the TCA column type color
| Name | Type | Scope |
|---|---|---|
| boolean | Proc. | |
| string | Display / Proc. | |
| array | ||
| array | ||
| array | ||
| string (keywords) | Display | |
| boolean | Proc. | |
| bool | ||
| string, hexadecimal color representation | Display | |
| boolean | Display | |
| boolean | Display / Proc. | |
| boolean | Display | |
| integer | Display | |
| array | Display |
-
-
- Type
- boolean
- Default
- false
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['behaviour']['allowLanguageSynchronization']
- Scope
- Proc.
Allows an editor to select in a localized record whether the value is copied over from default or source language record, or if the field has an own value in the localization. If set to true and if the table supports localization and if a localized record is edited, this setting enables FieldWizard LocalizationStateSelector: Two or three radio buttons shown below the field input. The state of this is stored in a json encoded array in the database table called
l10n_. It tells the DataHandler which fields of the localization records should be kept in sync if the underlying default or source record changes.state EXT:my_extension/Configuration/TCA/Overrides/150-tx_myextension_conference-color.php<?php use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; defined('TYPO3') or die(); ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [ 'color' => [ 'label' => 'my_extension.db:conference.color', 'config' => [ 'type' => 'color', 'valuePicker' => [ 'items' => [ ['label' => 'my_extension.db:conference.color.orange', 'value' => '#ff8700'], ['label' => 'my_extension.db:conference.color.teal', 'value' => '#2f99a4'], ['label' => 'my_extension.db:conference.color.night', 'value' => '#292545'], ], ], 'behaviour' => [ 'allowLanguageSynchronization' => true, ], 'searchable' => false, ], ], ]); ExtensionManagementUtility::addToAllTCAtypes( 'tx_myextension_conference', 'color', '', 'before:--div--;core.form.tabs:categories', );
-
- Type
- string
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['default']
- Scope
- Display / Proc.
Default value set if a new record is created. If empty, no color gets selected.
-
For details see fieldControl.
-
For details see fieldInformation.
-
-
- Type
- array
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['defaultLanguageDifferences']
For details see defaultLanguageDifferences.
-
- Type
- array
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['localizationStateSelector']
For details see localizationStateSelector.
-
- Type
- array
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['otherLanguageContent']
For details see otherLanguageContent.
-
- Type
- string (keywords)
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['mode']
- Scope
- Display
Possible keywords:
useOr Override Placeholder This property is related to the
placeholderproperty. When defined, a checkbox will appear above the field. If that box is checked, the field can be used to enter whatever the user wants as usual. If the box is not checked, the field becomes read-only and the value saved to the database will beNULL.Warning
In order for this property to apply properly, the DB column must be allowed to be
NULL, and propertynullablemust be set totrue.
-
- Type
- boolean
- Default
- false
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['nullable']
- Scope
- Proc.
If set to true, a checkbox will appear, which by default deactivates the field. In the deactivated state the field is saved as
NULLin the database. By activating the checkbox it is possible to set a value. If nothing is entered into the field, then an empty string will be saved and not aNULL.The database field must allow the
NULLvalue.
Example:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'overlay_color' => [
'label' => 'my_extension.db:conference.overlay_color',
'config' => [
'type' => 'color',
'opacity' => true,
'nullable' => true,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'overlay_color',
'',
'after:color',
);
-
- Type
- bool
- Default
- false
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['opacity']
- Added
- 13.3
If enabled, editors can select not only a color but also adjust its opacity (how transparent the color should be) in a color element.
Colors with an opacity are saved with the the
RRGGBBAAcolor notation.
The overlay color of a conference, half transparent
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'overlay_color' => [
'label' => 'my_extension.db:conference.overlay_color',
'config' => [
'type' => 'color',
'opacity' => true,
'nullable' => true,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'overlay_color',
'',
'after:color',
);
-
- Type
- string, hexadecimal color representation
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['placeholder']
- Scope
- Display
Placeholder, containing a hexadecimal color representation.
'placeholder' => '#ff8700', 'nullable' => true, 'mode' => 'useOrOverridePlaceholder',Copied!
-
- Type
- boolean
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['readOnly']
- Scope
- Display
Renders the field in a way that the user can see the value but cannot edit it.
Warning
This property affects only the display. It is still possible to write to those fields when using the DataHandler.
-
- Type
- boolean
- Default
- false
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['required']
- Scope
- Display / Proc.
If set to true a non-empty value is required in the field. Otherwise the form cannot be saved.
-
- Type
- boolean
- Default
true- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['searchable']
- Scope
- Display
New in version 14.0
TYPO3 now automatically includes all fields of suitable types in backend search operations in the Content > Records module.
This option can be used to explicitly exclude fields from being searchable, instead of having to list them in the now removed option $GLOBALS['TCA'][$table]['ctrl']['searchFields'].
By default, all fields of type
colorare considered searchable. To exclude a field from being searchable, set the following in the field's TCA configuration:EXT:my_extension/Configuration/TCA/Overrides/150-tx_myextension_conference-color.php<?php use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; defined('TYPO3') or die(); ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [ 'color' => [ 'label' => 'my_extension.db:conference.color', 'config' => [ 'type' => 'color', 'valuePicker' => [ 'items' => [ ['label' => 'my_extension.db:conference.color.orange', 'value' => '#ff8700'], ['label' => 'my_extension.db:conference.color.teal', 'value' => '#2f99a4'], ['label' => 'my_extension.db:conference.color.night', 'value' => '#292545'], ], ], 'behaviour' => [ 'allowLanguageSynchronization' => true, ], 'searchable' => false, ], ], ]); ExtensionManagementUtility::addToAllTCAtypes( 'tx_myextension_conference', 'color', '', 'before:--div--;core.form.tabs:categories', );
-
- Type
- integer
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['size']
- Scope
- Display
Abstract value for the width of the
<input>field. To set the field to the full width of the form area, use the value 50. Minimum is 10. Default is 30.
-
- Type
- array
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['valuePicker']
- Scope
- Display
Renders a select box with static values next to the input field. When an item is selected, the value replaces the current input value.
Changed in version 14.0 Breaking: #107677 - Drop prepend and append modes from TCA value picker
It is now recommended to define associative array keys for
itemsusinglabelandvalue. Existing numeric arrays are automatically migrated during TCA processing.The Value Picker always behaves like a replace operation. Previous
modevariants likeappendandprependwere removed.- items (array)
- A list of selectable items. Each item should be an associative array:
['label' => 'Shown label', 'value' => '#RRGGBB']. The label can be plain text or a label reference. Thevaluemust be a hex color with exactly 7 characters, including the leading hash (for example,'#FF8700').
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'color' => [
'label' => 'my_extension.db:conference.color',
'config' => [
'type' => 'color',
'valuePicker' => [
'items' => [
['label' => 'my_extension.db:conference.color.orange', 'value' => '#ff8700'],
['label' => 'my_extension.db:conference.color.teal', 'value' => '#2f99a4'],
['label' => 'my_extension.db:conference.color.night', 'value' => '#292545'],
],
],
'behaviour' => [
'allowLanguageSynchronization' => true,
],
'searchable' => false,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'color',
'',
'before:--div--;core.form.tabs:categories',
);