Examples
Example: Default checkboxes with fixed columns
[
'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.
[
'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
[
'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
[
'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
[
'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_
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',
],
],
],
];
The referenced items
method should populate the items
by filling $params
:
<?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'];
}
}
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.
[
'columns' => [
'checkbox_8' => [
'label' => 'checkbox_8',
'description' => 'eval=maximumRecordsCheckedInPid, for this PID',
'config' => [
'type' => 'check',
'eval' => 'maximumRecordsCheckedInPid',
'validation' => [
'maximumRecordsCheckedInPid' => 1,
],
],
],
],
]
Copied!