Radio buttons 

New in version 13.0

This type creates a set of radio buttons. The value is typically stored as integer value, each radio item has one assigned number, but it can be a string, too.

The according database field is generated automatically.

Example: Set of radio buttons field 

The level of a talk

The level of a talk

EXT:my_extension/Configuration/TCA/Overrides/230-tx_myextension_talk-level.php
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
  'level' => [
    'label' => 'my_extension.db:talk.level',
    'config' => [
      'type' => 'radio',
      'items' => [
        ['label' => 'my_extension.db:talk.level.beginner', 'value' => 1],
        ['label' => 'my_extension.db:talk.level.advanced', 'value' => 2],
        ['label' => 'my_extension.db:talk.level.expert', 'value' => 3],
      ],
      'default' => 1,
      'behaviour' => [
        'allowLanguageSynchronization' => true,
      ],
    ],
  ],
]);
ExtensionManagementUtility::addToAllTCAtypes(
  'tx_myextension_talk',
  'level',
  'talk,workshop',
  'before:--div--;core.form.tabs:access',
);
Copied!

Properties of the TCA column type radio 

Name Type Scope
boolean Proc.
string Display / Proc.
array
array
array Display / Proc.
array Display / Proc.
string (class->method reference) Display / Proc.
boolean Display
behaviour
allowLanguageSynchronization
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_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/230-tx_myextension_talk-level.php
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
  'level' => [
    'label' => 'my_extension.db:talk.level',
    'config' => [
      'type' => 'radio',
      'items' => [
        ['label' => 'my_extension.db:talk.level.beginner', 'value' => 1],
        ['label' => 'my_extension.db:talk.level.advanced', 'value' => 2],
        ['label' => 'my_extension.db:talk.level.expert', 'value' => 3],
      ],
      'default' => 1,
      'behaviour' => [
        'allowLanguageSynchronization' => true,
      ],
    ],
  ],
]);
ExtensionManagementUtility::addToAllTCAtypes(
  'tx_myextension_talk',
  'level',
  'talk,workshop',
  'before:--div--;core.form.tabs:access',
);
Copied!
default
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 radio gets selected.

fieldControl

For details see fieldControl.

fieldInformation

For details see fieldInformation.

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

For details see defaultLanguageDifferences.

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

For details see otherLanguageContent.

items
Type
array
Required

true

TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['items']
Scope
Display / Proc.

An array of values which can be selected.

Each entry is in itself an associative array.

label (plain text label or label reference)
The displayed title.
value (integer or string)
The value stored in the database.
itemsProcessors
Type
array
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['itemsProcessors']
Scope
Display / Proc.
Added
14.0

An array with numerical keys that can contain item processors implementing ItemsProcessorInterface .

Each item processor is executed sequentially based on its numerical array key. The item processor can add, modify or remove items from the SelectItemCollection , influencing which items are displayed.

EXT:my_extension/Configuration/TCA/Overrides/260-tx_myextension_talk-spoken_language.php
<?php

use MyVendor\MyExtension\Backend\ItemsProcessor\SpokenLanguageItemsProcessor;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
  'spoken_language' => [
    'label' => 'my_extension.db:talk.spoken_language',
    'config' => [
      'type' => 'radio',
      // Required for radio fields, the items come from the processor
      'items' => [],
      'itemsProcessors' => [
        100 => [
          'class' => SpokenLanguageItemsProcessor::class,
        ],
      ],
    ],
  ],
]);
ExtensionManagementUtility::addToAllTCAtypes(
  'tx_myextension_talk',
  'spoken_language',
  '',
  'after:abstract',
);
Copied!

A SelectItem for a field of type radio must be of type radio and must provide a label and value. The value can be an integer or string.

EXT:my_extension/Classes/Backend/ItemsProcessor/SpokenLanguageItemsProcessor.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Backend\ItemsProcessor;

use TYPO3\CMS\Core\DataHandling\ItemsProcessorContext;
use TYPO3\CMS\Core\DataHandling\ItemsProcessorInterface;
use TYPO3\CMS\Core\Schema\Struct\SelectItem;
use TYPO3\CMS\Core\Schema\Struct\SelectItemCollection;

/**
 * Offers the languages of the site as the language a talk is held in
 */
final readonly class SpokenLanguageItemsProcessor implements ItemsProcessorInterface
{
  public function processItems(
    SelectItemCollection $items,
    ItemsProcessorContext $context,
  ): SelectItemCollection {
    foreach ($context->site->getLanguages() as $language) {
      $items->add(new SelectItem(
        type: 'radio',
        label: $language->getTitle(),
        value: $language->getLocale()->getLanguageCode(),
      ));
    }
    return $items;
  }
}
Copied!

See also Item processor registration and implementation

itemsProcFunc
Type
string (class->method reference)
TCA path
$GLOBALS['TCA'][$table]['columns'][$field]['config']['itemsProcFunc']
Scope
Display / Proc.
Examples
the checkbox example with itemsProcFunc

PHP method which is called to fill or manipulate the items array. It is recommended to use the actual FQCN with class and then concatenate the method:

\MyVendor\MyExtension\UserFunction\FormEngine\YourClass::class . '->yourMethod'

This becomes handy when using an IDE and doing operations like renaming classes.

The provided method will have an array of parameters passed to it. The items array is passed by reference in the key items. By modifying the array of items, you alter the list of items. A method may throw an exception which will be displayed as a proper error message to the user.

Passed parameters
  • items (passed by reference)
  • config (TCA config of the field)
  • TSconfig (The matching itemsProcFunc TSconfig)
  • table (current table)
  • row (current database record)
  • field (current field name)
  • effectivePid (correct page ID)
  • site (current site)

The following parameter only exists if the field has a flex parent.

  • flexParentDatabaseRow

The following parameters are filled if the current record has an inline parent:

  • inlineParentUid
  • inlineParentTableName
  • inlineParentFieldName
  • inlineParentConfig
  • inlineTopMostParentUid
  • inlineTopMostParentTableName
  • inlineTopMostParentFieldName
readOnly
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.