Examples
Example: Default checkboxes with fixed columns
A single checkbox with a label
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'recording_allowed' => [
'label' => 'my_extension.db:talk.recording_allowed',
'config' => [
'type' => 'check',
'items' => [
['label' => 'my_extension.db:talk.recording_allowed.item'],
],
'behaviour' => [
'allowLanguageSynchronization' => true,
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'recording_allowed',
'talk,keynote',
'after:recording',
);
Example: Checkboxes with Inline columns and default value
The weekdays of a location, Monday to Friday checked by default
Monday to Friday, the first five bits, are active by default.
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_location', [
'open_days' => [
'label' => 'my_extension.db:location.open_days',
'config' => [
'type' => 'check',
'items' => [
['label' => 'my_extension.db:location.open_days.monday'],
['label' => 'my_extension.db:location.open_days.tuesday'],
['label' => 'my_extension.db:location.open_days.wednesday'],
['label' => 'my_extension.db:location.open_days.thursday'],
['label' => 'my_extension.db:location.open_days.friday'],
['label' => 'my_extension.db:location.open_days.saturday'],
['label' => 'my_extension.db:location.open_days.sunday'],
],
'cols' => 'inline',
// Monday to Friday: the first five bits
'default' => 31,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_location',
'open_days',
'',
'after:capacity',
);
Example: Checkbox limited to a maximal number of checked records
Only one location can be the main venue
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_location', [
'main_venue' => [
'label' => 'my_extension.db:location.main_venue',
'config' => [
'type' => 'check',
'items' => [
['label' => 'my_extension.db:location.main_venue.item'],
],
'eval' => 'maximumRecordsChecked',
'validation' => [
'maximumRecordsChecked' => 1,
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_location',
'main_venue',
'',
'after:name',
);
Note
The check counts the translations of a record as well. In a table with translations, translating a record with the checkbox set therefore fails. The locations of the conference extension have no translations.
Example: Toggle checkbox with invertStateDisplay
'hidden' => [
'label' => 'core.db.general:enabled',
'exclude' => true,
'config' => [
'type' => 'check',
'renderType' => 'checkboxToggle',
'default' => 0,
'items' => [
[
'label' => '',
'invertStateDisplay' => true,
],
],
],
],
Example: Checkboxes with icons
Two tasks are finished, one is still open
Each checkbox of the preparation of a talk shows a tick in a circle when it is checked, and a clock when it is not:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'checklist' => [
'label' => 'my_extension.db:talk.checklist',
'config' => [
'type' => 'check',
// A finished task shows a tick in a circle, an open task a clock
'items' => [
[
'label' => 'my_extension.db:talk.checklist.slides',
'iconIdentifierChecked' => 'actions-check-circle',
'iconIdentifierUnchecked' => 'actions-clock',
],
[
'label' => 'my_extension.db:talk.checklist.recording',
'iconIdentifierChecked' => 'actions-check-circle',
'iconIdentifierUnchecked' => 'actions-clock',
],
[
'label' => 'my_extension.db:talk.checklist.technical_check',
'iconIdentifierChecked' => 'actions-check-circle',
'iconIdentifierUnchecked' => 'actions-clock',
],
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'checklist',
'',
'before:--div--;core.form.tabs:access',
);
Example: Checkboxes with itemsProcFunc
An items adds items to the checkboxes. See the
example of itemsProcFunc,
which adds the tracks of a conference to a select field.
The conference extension adds the days of a talk with the newer itemsProcessors instead, which read the dates of the conference.
Example: checkboxToggle
A toggle
Example: checkboxLabeledToggle
A toggle with the labels Open and Closed
Example: Only one record on a page can be checked
Each conference keeps its hotels in a folder of its own. Only one hotel in a folder can be the recommended hotel:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_hotel', [
'recommended' => [
'label' => 'my_extension.db:hotel.recommended',
'config' => [
'type' => 'check',
'items' => [
['label' => 'my_extension.db:hotel.recommended.item'],
],
// Each conference keeps its hotels in a folder of its own and
// recommends one of them
'eval' => 'maximumRecordsCheckedInPid',
'validation' => [
'maximumRecordsCheckedInPid' => 1,
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_hotel',
'recommended',
'',
'after:name',
);