selectCheckBox and type check fields compared
There is a subtle difference between select fields with the render type selectCheckBox and fields of the type check:
Select values from a checkbox list
The topics of a speaker
The select checkbox stores the values as comma separated values.
EXT:my_extension/Configuration/TCA/Overrides/332-tx_myextension_speaker-topics.php
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_speaker', [
'topics' => [
'label' => 'my_extension.db:speaker.topics',
'config' => [
'type' => 'select',
'renderType' => 'selectCheckBox',
'items' => [
[
'label' => 'my_extension.db:speaker.topics.tca',
'value' => 'tca',
'group' => 'backend',
'icon' => 'content-database',
'description' => 'my_extension.db:speaker.topics.tca.description',
],
['label' => 'my_extension.db:speaker.topics.extbase', 'value' => 'extbase', 'group' => 'backend'],
['label' => 'my_extension.db:speaker.topics.fluid', 'value' => 'fluid', 'group' => 'frontend'],
['label' => 'my_extension.db:speaker.topics.typoscript', 'value' => 'typoscript', 'group' => 'frontend'],
['label' => 'my_extension.db:speaker.topics.accessibility', 'value' => 'accessibility', 'group' => 'frontend'],
],
'itemGroups' => [
'backend' => 'my_extension.db:speaker.topics.group.backend',
'frontend' => 'my_extension.db:speaker.topics.group.frontend',
],
'appearance' => [
'expandAll' => true,
],
'behaviour' => [
'allowLanguageSynchronization' => true,
],
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_speaker',
'topics',
'',
'after:short_bio',
);
The field in the database is of type text or varchar.
CREATE TABLE tx_myextension_speaker (
topics text
);
Copied!
Select values from a checkbox list
The amenities of a conference
On the contrary the type check saves multiple values
as bits. Therefore if the first value is chosen it stores 1 (binary 00000001),
if only the second is chosen it stores 2 (binary 00000010) and if both are
chosen 3 (binary 00000011).
EXT:my_extension/Configuration/TCA/Overrides/136-tx_myextension_conference-amenities.php
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'amenities' => [
'label' => 'my_extension.db:conference.amenities',
'config' => [
'type' => 'check',
'items' => [
['label' => 'my_extension.db:conference.amenities.catering'],
['label' => 'my_extension.db:conference.amenities.childcare'],
['label' => 'my_extension.db:conference.amenities.live_stream'],
['label' => 'my_extension.db:conference.amenities.wheelchair_access'],
],
'cols' => 3,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'amenities',
'',
'after:ticketing_secret',
);
The field in the database is of type int.
CREATE TABLE tx_myextension_conference (
amenities int(11) DEFAULT '0' NOT NULL
);
Copied!