Examples

Example: Default checkboxes with fixed columns

EXT:styleguide/Configuration/TCA/tx_styleguide_elements_basic.php
[
    'columns' => [
        'checkbox_2' => [
            'label' => 'checkbox_2',
            'description' => 'one checkbox with label',
            'config' => [
                'type' => 'check',
                'items' => [
                    [
                        'label' => 'foo',
                    ],
                ],
            ],
        ],
    ],
]
Copied!

Example: Checkboxes with Inline columns and default value

Here "Tu", the second bit, is active by default.

EXT:styleguide/Configuration/TCA/tx_styleguide_elements_basic.php
[
    'columns' => [
        'checkbox_16' => [
            'label' => 'checkbox_16',
            'description' => 'cols=inline',
            'config' => [
                'type' => 'check',
                'items' => [
                    [
                        'label' => 'Mo',
                    ],
                    [
                        'label' => 'Tu',
                    ],
                    [
                        'label' => 'We',
                    ],
                    [
                        'label' => 'Th',
                    ],
                    [
                        'label' => 'Fr',
                    ],
                    [
                        'label' => 'Sa',
                    ],
                    [
                        'label' => 'Su',
                    ],
                ],
                'cols' => 'inline',
            ],
        ],
    ],
]
Copied!

Example: Checkbox limited to a maximal number of checked records

EXT:styleguide/Configuration/TCA/tx_styleguide_elements_basic.php
[
    'columns' => [
        'checkbox_7' => [
            'label' => 'checkbox_7',
            'description' => 'eval=maximumRecordsChecked, table wide',
            'config' => [
                'type' => 'check',
                'eval' => 'maximumRecordsChecked',
                'validation' => [
                    'maximumRecordsChecked' => 1,
                ],
            ],
        ],
    ],
]
Copied!

Example: Toggle checkbox with invertStateDisplay

EXT:styleguide/Configuration/TCA/tx_styleguide_elements_basic.php
[
    'columns' => [
        'checkbox_18' => [
            'label' => 'checkbox_18',
            'description' => 'renderType=checkboxToggle single inverted state display',
            'config' => [
                'type' => 'check',
                'renderType' => 'checkboxToggle',
                'items' => [
                    [
                        'label' => 'foo',
                        'invertStateDisplay' => true,
                    ],
                ],
            ],
        ],
    ],
]
Copied!

Example: Three checkboxes, two with labels, one without

EXT:styleguide/Configuration/TCA/tx_styleguide_elements_basic.php
[
    'columns' => [
        'checkbox_3' => [
            'label' => 'checkbox_3',
            'description' => 'three checkboxes, two with labels, one without',
            'config' => [
                'type' => 'check',
                'items' => [
                    [
                        'label' => 'foo',
                    ],
                    [
                        'label' => '',
                    ],
                    [
                        'label' => 'foobar',
                        'iconIdentifierChecked' => 'content-beside-text-img-below-center',
                        'iconIdentifierUnchecked' => 'content-beside-text-img-below-center',
                    ],
                ],
            ],
        ],
    ],
]
Copied!

Example: Checkboxes with itemsProcFunc

The configuration for a custom field select_single_2 could look like this:

<?php

use MyVendor\MyExtension\UserFunctions\MyItemsProcFunc;

return [
    'columns' => [
        'checkbox_itemsProcFunc' => [
            'exclude' => 1,
            'label' => 'checkbox itemsProcFunc',
            'config' => [
                'type' => 'check',
                'items' => [
                    ['label' => 'foo', 'value' => 1],
                    ['label' => 'bar', 'value' => 'bar'],
                ],
                'itemsProcFunc' => MyItemsProcFunc::class . '->itemsProcFunc',
            ],
        ],
    ],
];
Copied!

The referenced itemsProcFunc method should populate the items by filling $params['items']:

<?php

class MyItemsProcFunc
{
    /**
     * Add two items to existing ones
     */
    public function itemsProcFunc(array &$params): void
    {
        $params['items'][] = ['label' => 'item 1 from itemProcFunc()', 'value' => 'val1'];
        $params['items'][] = ['label' => 'item 2 from itemProcFunc()', 'value' => 'val2'];
    }
}
Copied!

In the real world you would use the other passed parameters to dynamically generate the items.

Example: checkboxToggle

Example: checkboxLabeledToggle

Example: Only one record can be checked

In the example below, only one record from the same table will be allowed to have that particular box checked.

EXT:styleguide/Configuration/TCA/tx_styleguide_elements_basic.php
[
    'columns' => [
        'checkbox_8' => [
            'label' => 'checkbox_8',
            'description' => 'eval=maximumRecordsCheckedInPid, for this PID',
            'config' => [
                'type' => 'check',
                'eval' => 'maximumRecordsCheckedInPid',
                'validation' => [
                    'maximumRecordsCheckedInPid' => 1,
                ],
            ],
        ],
    ],
]
Copied!