BooleanGroup#

BooleanGroup holds named on/off options, booleanGroup in the descriptor, shown as one cell and edited as one group of checkboxes, in a bool column each or in one JSON column. A flag group holds several named on/off options as one value: a list shows the labels of the ones that are on, a form a group of checkboxes.

BooleanGroup::make('contact', 'Contact by')
    ->options(['newsletter' => 'Newsletter', 'acceptsSms' => 'Text message', 'acceptsPost' => 'Post'])
    ->sortable()->filterable(),                                     // columns mode: three bool properties

BooleanGroup::make('flags')
    ->options(['vip' => 'VIP customer', 'legalHold' => 'Legal hold'])
    ->json()->filterable(),                                         // JSON mode: one array property
A BooleanGroup field on a customer profile's form: Contact by, with checkboxes for Newsletter, Text message and Post
A BooleanGroup field on a customer profile's form: Contact by, with checkboxes for Newsletter, Text message and Post

On the wire the value is an object of every option key to true or false: {"newsletter": true, "acceptsSms": false, "acceptsPost": true}. A key a write leaves out is false, so a write sets every flag. An option key is a name of letters, digits and underscores.

Storage#

Mode

Property

Column

Columns (the default)

one non-null bool property per option key; the field’s own name is no property

a boolean column each (TINYINT(1) on MySQL, BOOLEAN on PostgreSQL)

JSON (json())

the field’s own array or ?array property

JSON on MySQL and MariaDB, jsonb on PostgreSQL, holding the object

The build refuses a mismatch and converts nothing: an option key that is not a non-null bool property in columns mode, a group named after a property in columns mode, a flag that is also declared as a field of its own (the group writes it), JSON mode on a property that is not an array, a group without options, a default() that is not an object of some of its keys to booleans, and two columns-mode groups naming the same flag. A columns-mode group also counts as writing its flags’ properties when the build checks that a record can be created. When every flag’s property declares a default (private bool $acceptsSms = false;) and the group has no default() of its own, the group defaults to those values, so a create may leave it out and stores them; when one of them declares none, a create must send the group. Bit masks are not supported.

Strict keys#

A write naming a key that is no option is refused with invalid_choice on that key (contact/acceptsFax), and a value that is not a boolean with type_mismatch. In JSON mode a stored key missing from the object reads as false, and a stored key that is no option throws Kinetis\Vector\Exception\StoredValueException on read. Removing an option therefore needs a data migration first: remove the key from the stored objects (or drop its column in columns mode), then remove it from the field.

Filters and sorting#

Both modes filter the group with any (at least one of the listed keys is on, the default) and all (every one of them is on):

GET /vector/r/customer-profiles?filter[contact][any]=acceptsSms,acceptsPost
GET /vector/r/tickets?filter[flags][all]=vip,legalHold
GET /vector/r/tickets?filter[flags]=vip                       # a bare value is "any"

A nullable JSON column adds null and nnull. In JSON mode each key travels inside a bound {"key": true} object matched by containment (JSON_CONTAINS on MySQL and MariaDB, @> on PostgreSQL), and only keys the field declares are accepted.

In columns mode each flag is also a boolean of its own, named group.key: it filters with eq when the group is filterable() and sorts when the group is sortable(). The group itself is not sortable.

GET /vector/r/customer-profiles?filter[contact.acceptsSms]=true
GET /vector/r/customer-profiles?filter[contact.newsletter][eq]=false&sort=-contact.acceptsPost

A JSON-mode group is never sortable; the build refuses sortable() on it. No flag group is grouped, summarized, searched or edited inline, and a form condition cannot test one. A CSV import reads the group’s cell as the JSON object an export writes.

It takes the common modifiers too.