Color
New in version 12.0
The TCA type color
has been introduced. It replaces the
render
of TCA type input
. See
Migration: from renderType colorpicker to TCA type color.
The TCA type color
should be used to render a JavaScript-based color picker.
Table of contents
Example: Define a simple color picker in TCA
A simple color picker:
$aColorField' = [
'label' => 'Color field',
'config' => [
'type' => 'color',
]
];
Properties of the TCA column type color
behaviour
-
allowLanguageSynchronization
-
- Type
- boolean
- Default
- false
- 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
default
-
- Type
- string
- 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.
fieldControl
-
For details see fieldControl.
fieldInformation
-
For details see fieldInformation.
fieldWizard
-
defaultLanguageDifferences
-
- Type
- array
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['defaultLanguageDifferences']
For details see defaultLanguageDifferences.
localizationStateSelector
-
- Type
- array
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['localizationStateSelector']
For details see localizationStateSelector.
otherLanguageContent
-
- Type
- array
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['otherLanguageContent']
For details see otherLanguageContent.
mode
-
- Type
- string (keywords)
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['mode']
- Scope
- Display
Possible keywords:
use
Or Override Placeholder This property is related to the
placeholder
property. 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 propertynullable
must be set totrue
.
nullable
-
- Type
- boolean
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']
- Default
- false
- 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
NULL
in 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
NULL
value.
Example:
.. _columns-color-properties-nullable:
.. confval:: nullable
:name: color-nullable
:Path: $GLOBALS['TCA'][$table]['columns'][$field]['config']
:type: boolean
:Default: false
: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 :sql:`NULL` in 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 a :sql:`NULL`.
The database field must allow the :sql:`NULL` value.
Example:
.. literalinclude:: _Properties/_Nullable.rst.txt
:caption: EXT:some_extension/Configuration/TCA/tx_sometable.php
placeholder
-
- Type
- string, hexadecimal color representation
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['placeholder']
- Scope
- Display
readOnly
-
- Type
- boolean
- 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.
required
-
- Type
- boolean
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']
- Scope
- Display / Proc.
- Default
- false
If set to true a non-empty value is required in the field. Otherwise the form cannot be saved.
size
-
- Type
- integer
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']
- 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.
valuePicker
-
- Type
- array
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']
- Scope
- Display
Renders a select box with static values next to the input field. When a value is selected in the box, the value is transferred to the field. Keys:
- items (array)
- An array with selectable items. Each item is an array with the first value being the label in the select drop-down (LLL reference possible) the second being the hex-value transferred to the input field. The value should have exactly 7 characters, as this is the maximum for a hex-value.
Migration: from renderType colorpicker
to TCA type color
A complete migration from render
to type=color
looks like the following:
'a_color_field' => [
'label' => 'Color field',
'config' => [
- 'type' => 'input',
- 'renderType' => 'colorpicker',
+ 'type' => 'color',
'required' => true,
'size' => 20,
- 'max' => 1024,
- 'eval' => 'trim',
'valuePicker' => [
'items' => [
['typo3 orange', '#FF8700'],
],
],
],
],
An automatic TCA migration is performed on the fly, migrating all occurrences
to the new TCA type and triggering a PHP E_
error
where code adoption has to take place.