Choice

Use the choice type for fields whose value must be a member of a list.

Included in the PerformBaseBundle.

Options

choices

An array of choices, where the keys are the labels, and values the possible value.

This option is required.

Allowed types: array

Defaults:

  • List context: No default
  • View context: No default
  • Create context: No default
  • Edit context: No default

label

The label to use for form labels and table headings. If no label is provided, a sensible label will be created automatically.

This option is optional.

Allowed types: string

Defaults:

  • List context: No default
  • View context: No default
  • Create context: No default
  • Edit context: No default

show_label

If true, display the choice label instead of the value in list and view contexts.

This option is optional.

Allowed types: boolean

Defaults:

  • List context: true
  • View context: true
  • Create context: true
  • Edit context: true

unknown_label

The value to show when show_label is true and the value is not in the list of choices.

This option is optional.

Allowed types: string

Defaults:

  • List context: ''
  • View context: ''
  • Create context: ''
  • Edit context: ''

Example

<?php
$config->add('status', [
    'type' => 'choice',
    'options' => [
        'choices' => [
            'Started' => 1,
            'In Progress' => 2,
            'Done' => 3,
        ],
    ],
    'sort' => false,
]);