Color

New in version 13.0

The TCA type color should be used to render a JavaScript-based color picker. The according database field is generated automatically.

New in version 13.0

Color palettes can be defined via page TSconfig. This way, for example, colors defined in a corporate design can be selected by a simple click.

Example: Define a simple color picker in TCA

A simple color picker:

$aColorField' = [
    'label' => 'Color field',
    'config' => [
        'type' => 'color',
    ]
];
Copied!

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.
integer Display
array Display

behaviour

behaviour

allowLanguageSynchronization

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_state. It tells the DataHandler which fields of the localization records should be kept in sync if the underlying default or source record changes.

EXT:my_extension/Configuration/TCA/Overrides/someTable.php
<?php

$colorField = [
    'config' => [
        'type' => 'color',
        'behaviour' => [
            'allowLanguageSynchronization' => true,
        ],
    ],
];
Copied!

default

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

fieldControl

For details see fieldControl.

fieldInformation

fieldInformation

For details see fieldInformation.

fieldWizard

fieldWizard

defaultLanguageDifferences

defaultLanguageDifferences
Type
array
Path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['defaultLanguageDifferences']

For details see defaultLanguageDifferences.

localizationStateSelector

localizationStateSelector
Type
array
Path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['localizationStateSelector']

For details see localizationStateSelector.

otherLanguageContent

otherLanguageContent
Type
array
Path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['fieldWizard']['otherLanguageContent']

For details see otherLanguageContent.

mode

mode
Type
string (keywords)
Path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['mode']
Scope
Display

Possible keywords: useOrOverridePlaceholder

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 be NULL.

nullable

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 a NULL.

The database field must allow the NULL value.

Example:

EXT:some_extension/Configuration/TCA/tx_sometable.php
..  _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


Copied!

opacity

opacity
Type
bool
Default
false
Path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['opacity']

New in version 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 RRGGBBAA color notation.

Example: Allow adjustment of opacity in a color picker
A color picker with adjustable opacity

A color picker with adjustable opacity

EXT:my_extension/Configuration/TCA/Overrides/some_table.php
$temporaryColumns['aColorField'] = [
    'label' => 'My Color',
    'config' => [
        'type' => 'color',
        'opacity' => true,
    ],
];
Copied!

placeholder

placeholder
Type
string, hexadecimal color representation
Path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['placeholder']
Scope
Display

Placeholder, containing a hexadecimal color representation.

<?php

$temporaryColumns['aColorField'] = [
    'title' => 'My color field',
    'config' => [
        'type' => 'color',
        'placeholder' => '#FF8700',
        'mode' => 'useOrOverridePlaceholder',
    ],
];
Copied!

readOnly

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.

required

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

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

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.
Example
EXT:my_extension/Configuration/TCA/Overrides/some_table.php
<?php

$temporaryColumns['aColorField'] = [
    'label' => 'Color field',
    'config' => [
        'type' => 'color',
        'required' => true,
        'size' => 20,
        'valuePicker' => [
            'items' => [
                ['typo3 orange', '#FF8700'],
            ],
        ],
    ],
];
Copied!