Labeled toggle checkbox
The checkbox type with the renderType checkboxLabeledToggle is displayed as a toggle switch where both states can be labelled (ON / OFF, Visible / Hidden or alike).
Its state can be inverted via invertStateDisplay
Examples
Single checkbox with labeled toggle
A toggle with the labels Open and Closed
EXT:my_extension/Configuration/TCA/Overrides/116-tx_myextension_conference-registration_open.php
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'registration_open' => [
'label' => 'my_extension.db:conference.registration_open',
'onChange' => 'reload',
'config' => [
'type' => 'check',
'renderType' => 'checkboxLabeledToggle',
'items' => [
[
'label' => 'my_extension.db:conference.registration_open',
'labelChecked' => 'my_extension.db:conference.registration_open.open',
'labelUnchecked' => 'my_extension.db:conference.registration_open.closed',
],
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'registration_open',
'',
'after:published',
);
Single checkbox with labeled toggle inverted state display
The field stores 1 when the comments on a talk are closed. With
invert, the toggle is on while the comments are open. The
labels label and label follow the displayed state of the
toggle, not the stored value:
The toggle is on, and the comments are open
EXT:my_extension/Configuration/TCA/Overrides/256-tx_myextension_talk-comments_closed.php
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'comments_closed' => [
'label' => 'my_extension.db:talk.comments_closed',
'config' => [
'type' => 'check',
'renderType' => 'checkboxLabeledToggle',
'items' => [
[
'label' => 'my_extension.db:talk.comments_closed',
// The toggle is on while the comments are open
'invertStateDisplay' => true,
'labelChecked' => 'my_extension.db:talk.comments_closed.open',
'labelUnchecked' => 'my_extension.db:talk.comments_closed.closed',
],
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'comments_closed',
'',
'before:comments',
);