Country picker TCA type
New in version 14.0
The TCA type
country
can be used to render a country picker. Its main
purpose is to use the
Country API to provide
a country selection in the backend and use the stored representation in Extbase
or TypoScript output.
Table of contents
Example: Define a basic country picker

The following code displays a basic country picker with Suisse (Iso code CH
)
as default value. The localized name is displayed to the backend users.
Extended country picker example
The following example demonstrates most of the properties of the country picker TCA type:
<?php
return [
// ...
'columns' => [
'my-country' => [
'label' => 'Country of Receiver',
'config' => [
'type' => 'country',
// available options: name, localizedName, officialName, localizedOfficialName, iso2, iso3
'labelField' => 'iso2',
// countries which are listed before all others
'prioritizedCountries' => ['AT', 'CH'],
// sort by the label
'sortItems' => [
'label' => 'asc',
],
'filter' => [
// restrict to the given country ISO2 or ISO3 codes
'onlyCountries' => ['DE', 'AT', 'CH', 'FR', 'IT', 'HU', 'US', 'GR', 'ES'],
// exclude by the given country ISO2 or ISO3 codes
'excludeCountries' => ['DE', 'ES'],
],
'default' => 'HU',
// When required=false, an empty selection ('') is possible
'required' => false,
],
],
],
];
<settings.country>
<label>Country</label>
<config>
<type>country</type>
<labelField>iso2</labelField>
<prioritizedCountries>
<numIndex index="0">AT</numIndex>
<numIndex index="1">CH</numIndex>
</prioritizedCountries>
<filter>
<onlyCountries>
<numIndex index="0">DE</numIndex>
<numIndex index="1">AT</numIndex>
<numIndex index="2">CH</numIndex>
<numIndex index="3">FR</numIndex>
<numIndex index="4">IT</numIndex>
<numIndex index="5">HU</numIndex>
<numIndex index="6">US</numIndex>
<numIndex index="7">GR</numIndex>
<numIndex index="8">ES</numIndex>
</onlyCountries>
<excludeCountries>
<numIndex index="0">DE</numIndex>
<numIndex index="1">ES</numIndex>
</excludeCountries>
</filter>
<sortItems>
<label>asc</label>
</sortItems>
<default>HU</default>
<required>0</required>
</config>
</settings.country>
Additional countries can be added via the BeforeCountriesEvaluatedEvent.
Properties of TCA column type country
Name | Type | Scope |
---|---|---|
string | Display / Proc. | |
array of strings | Display | |
array of strings | Display | |
string, one of localized , name , iso2 , iso3 , official , localized
|
Display | |
array of strings | Display | |
boolean | Display | |
boolean | Display / Proc. | |
integer | Display | |
string, one of asc , desc
|
Display |
default
-
- Type
- string
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['default']
- Scope
- Display / Proc.
Default value as ISO2 code set if a new record is created. If empty, no country gets selected.
filter
-
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['filter']
onlyCountries
-
- Type
- array of strings
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['filter']['onlyCountries']
- Scope
- Display
- Default
[]
- Example
['DE', 'AT', 'CH']
Restrict the displayed countries (ISO2 or ISO3 codes) to the ones listed.
Additional countries can be added via the BeforeCountriesEvaluatedEvent.
excludeCountries
-
- Type
- array of strings
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['filter']['excludeCountries']
- Scope
- Display
- Default
[]
- Example
['DE', 'AT', 'CH']
Exclude the countries (ISO2 or ISO3 codes) in this list from being displayed in the selector.
labelField
-
- Type
- string, one of
localized
,Name name
,iso2
,iso3
,official
,Name localized
Official Name - Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['labelField']
- Scope
- Display
- Default
name
prioritizedCountries
-
- Type
- array of strings
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['prioritizedCountries']
- Scope
- Display
- Default
[]
- Example
['DE', 'AT', 'CH']
Countries (ISO2 or ISO3 codes) which are listed before all others countries.
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']['size']
- Scope
- Display
- Default
- 1
If set to 1 (default), displays a select drop-down, else a select box of given size.
sortItems.label
-
- Type
- string, one of
asc
,desc
- Path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['sortItems']['label']
- Scope
- Display
- Default
asc
Sort order of the select items in the country picker.