ChoiceField
in package
implements
FieldInterface
Uses
FieldTrait
Tags
Table of Contents
Interfaces
Constants
- OPTION_ALLOW_MULTIPLE_CHOICES = 'allowMultipleChoices'
- OPTION_AUTOCOMPLETE = 'autocomplete'
- OPTION_CHOICES = 'choices'
- OPTION_ESCAPE_HTML_CONTENTS = 'escapeHtml'
- OPTION_RENDER_AS_BADGES = 'renderAsBadges'
- OPTION_RENDER_EXPANDED = 'renderExpanded'
- OPTION_USE_TRANSLATABLE_CHOICES = 'useTranslatableChoices'
- OPTION_WIDGET = 'widget'
- VALID_BADGE_TYPES = ['success', 'warning', 'danger', 'info', 'primary', 'secondary', 'light', 'dark']
- WIDGET_AUTOCOMPLETE = 'autocomplete'
- WIDGET_NATIVE = 'native'
Properties
Methods
- addCssClass() : self
- addCssFiles() : self
- addFormTheme() : self
- addHtmlContentsToBody() : self
- addHtmlContentsToHead() : self
- addJsFiles() : self
- addWebpackEncoreEntries() : self
- allowMultipleChoices() : self
- autocomplete() : self
- escapeHtml() : self
- formatValue() : self
- getAsDto() : FieldDto
- hideOnDetail() : self
- hideOnForm() : self
- hideOnIndex() : self
- hideWhenCreating() : self
- hideWhenUpdating() : self
- new() : self
- onlyOnDetail() : self
- onlyOnForms() : self
- onlyOnIndex() : self
- onlyWhenCreating() : self
- onlyWhenUpdating() : self
- renderAsBadges() : self
- Possible values of $badgeSelector: * true: all values are displayed as 'secondary' badges * false: no badges are displayed; values are displayed as regular text * array: [$fieldValue => $badgeType, ...] (e.g. ['foo' => 'primary', 7 => 'warning', 'cancelled' => 'danger']) * callable: function(FieldDto $field): string { return '...' } (e.g. function(FieldDto $field) { return $field->getValue() < 10 ? 'warning' : 'primary'; }).
- renderAsNativeWidget() : self
- renderExpanded() : self
- setChoices() : self
- Given choices must follow the same format used in Symfony Forms: ['Label visible to users' => 'submitted_value', ...].
- setColumns() : self
- setCssClass() : self
- setCustomOption() : self
- setCustomOptions() : self
- setDisabled() : self
- setEmptyData() : self
- setFieldFqcn() : self
- setFormattedValue() : self
- setFormType() : self
- setFormTypeOption() : self
- setFormTypeOptionIfNotSet() : self
- setFormTypeOptions() : self
- setHelp() : self
- setLabel() : self
- setPermission() : self
- setProperty() : self
- setRequired() : self
- setSortable() : self
- setTemplateName() : self
- setTemplatePath() : self
- setTextAlign() : self
- setTranslatableChoices() : self
- When the contents of the choices use translatable objects, you can't use the setChoices() method because PHP doesn't allow using objects as array keys.
- setTranslationParameters() : self
- setValue() : self
- setVirtual() : self
- __construct() : mixed
Constants
OPTION_ALLOW_MULTIPLE_CHOICES
public
mixed
OPTION_ALLOW_MULTIPLE_CHOICES
= 'allowMultipleChoices'
OPTION_AUTOCOMPLETE
public
mixed
OPTION_AUTOCOMPLETE
= 'autocomplete'
OPTION_CHOICES
public
mixed
OPTION_CHOICES
= 'choices'
OPTION_ESCAPE_HTML_CONTENTS
public
mixed
OPTION_ESCAPE_HTML_CONTENTS
= 'escapeHtml'
OPTION_RENDER_AS_BADGES
public
mixed
OPTION_RENDER_AS_BADGES
= 'renderAsBadges'
OPTION_RENDER_EXPANDED
public
mixed
OPTION_RENDER_EXPANDED
= 'renderExpanded'
OPTION_USE_TRANSLATABLE_CHOICES
public
mixed
OPTION_USE_TRANSLATABLE_CHOICES
= 'useTranslatableChoices'
OPTION_WIDGET
public
mixed
OPTION_WIDGET
= 'widget'
VALID_BADGE_TYPES
public
mixed
VALID_BADGE_TYPES
= ['success', 'warning', 'danger', 'info', 'primary', 'secondary', 'light', 'dark']
WIDGET_AUTOCOMPLETE
public
mixed
WIDGET_AUTOCOMPLETE
= 'autocomplete'
WIDGET_NATIVE
public
mixed
WIDGET_NATIVE
= 'native'
Properties
$dto
private
FieldDto
$dto
Methods
addCssClass()
public
addCssClass(string $cssClass) : self
Parameters
- $cssClass : string
Return values
selfaddCssFiles()
public
addCssFiles(Asset|string ...$pathsOrAssets) : self
Parameters
- $pathsOrAssets : Asset|string
Return values
selfaddFormTheme()
public
addFormTheme(string ...$formThemePaths) : self
Parameters
- $formThemePaths : string
Return values
selfaddHtmlContentsToBody()
public
addHtmlContentsToBody(string ...$contents) : self
Parameters
- $contents : string
Return values
selfaddHtmlContentsToHead()
public
addHtmlContentsToHead(string ...$contents) : self
Parameters
- $contents : string
Return values
selfaddJsFiles()
public
addJsFiles(Asset|string ...$pathsOrAssets) : self
Parameters
- $pathsOrAssets : Asset|string
Return values
selfaddWebpackEncoreEntries()
public
addWebpackEncoreEntries(Asset|string ...$entryNamesOrAssets) : self
Parameters
- $entryNamesOrAssets : Asset|string
Return values
selfallowMultipleChoices()
public
allowMultipleChoices([bool $allow = true ]) : self
Parameters
- $allow : bool = true
Return values
selfautocomplete()
public
autocomplete() : self
Return values
selfescapeHtml()
public
escapeHtml([bool $escape = true ]) : self
Parameters
- $escape : bool = true
Return values
selfformatValue()
public
formatValue(callable|null $callable) : self
Parameters
- $callable : callable|null
Return values
selfgetAsDto()
public
getAsDto() : FieldDto
Return values
FieldDtohideOnDetail()
public
hideOnDetail() : self
Return values
selfhideOnForm()
public
hideOnForm() : self
Return values
selfhideOnIndex()
public
hideOnIndex() : self
Return values
selfhideWhenCreating()
public
hideWhenCreating() : self
Return values
selfhideWhenUpdating()
public
hideWhenUpdating() : self
Return values
selfnew()
public
static new(string $propertyName[, TranslatableInterface|string|false|null $label = null ]) : self
Parameters
- $propertyName : string
- $label : TranslatableInterface|string|false|null = null
Return values
selfonlyOnDetail()
public
onlyOnDetail() : self
Return values
selfonlyOnForms()
public
onlyOnForms() : self
Return values
selfonlyOnIndex()
public
onlyOnIndex() : self
Return values
selfonlyWhenCreating()
public
onlyWhenCreating() : self
Return values
selfonlyWhenUpdating()
public
onlyWhenUpdating() : self
Return values
selfrenderAsBadges()
Possible values of $badgeSelector: * true: all values are displayed as 'secondary' badges * false: no badges are displayed; values are displayed as regular text * array: [$fieldValue => $badgeType, ...] (e.g. ['foo' => 'primary', 7 => 'warning', 'cancelled' => 'danger']) * callable: function(FieldDto $field): string { return '...' } (e.g. function(FieldDto $field) { return $field->getValue() < 10 ? 'warning' : 'primary'; }).
public
renderAsBadges([mixed $badgeSelector = true ]) : self
Possible badge types: 'success', 'warning', 'danger', 'info', 'primary', 'secondary', 'light', 'dark'
Parameters
- $badgeSelector : mixed = true
Return values
selfrenderAsNativeWidget()
public
renderAsNativeWidget([bool $asNative = true ]) : self
Parameters
- $asNative : bool = true
Return values
selfrenderExpanded()
public
renderExpanded([bool $expanded = true ]) : self
Parameters
- $expanded : bool = true
Return values
selfsetChoices()
Given choices must follow the same format used in Symfony Forms: ['Label visible to users' => 'submitted_value', ...].
public
setChoices(mixed $choiceGenerator) : self
If the contents of the choice values are translatable objects, use the setTranslatableChoices() method instead: ['submitted_value' => t('Label visible to users'), ...].
In addition to an array, you can use a PHP callback, which is passed the instance of the current entity (it can be null) and the FieldDto as the second argument: ->setChoices(fn () => ['foo' => 1, 'bar' => 2]) ->setChoices(fn (?MyEntity $foo) => $foo->someField()->getChoices()) ->setChoices(fn (?MyEntity $foo, FieldDto $field) => ...)
Parameters
- $choiceGenerator : mixed
Return values
selfsetColumns()
public
setColumns(int|string $cols) : self
Parameters
- $cols : int|string
-
An integer with the number of columns that this field takes (e.g. 6), or a string with responsive col CSS classes (e.g. 'col-6 col-sm-4 col-lg-3')
Return values
selfsetCssClass()
public
setCssClass(string $cssClass) : self
Parameters
- $cssClass : string
Return values
selfsetCustomOption()
public
setCustomOption(string $optionName, mixed $optionValue) : self
Parameters
- $optionName : string
- $optionValue : mixed
Return values
selfsetCustomOptions()
public
setCustomOptions(array<string|int, mixed> $options) : self
Parameters
- $options : array<string|int, mixed>
Return values
selfsetDisabled()
public
setDisabled([bool $disabled = true ]) : self
Parameters
- $disabled : bool = true
Return values
selfsetEmptyData()
public
setEmptyData([mixed $emptyData = null ]) : self
Parameters
- $emptyData : mixed = null
Return values
selfsetFieldFqcn()
public
setFieldFqcn(string $fieldFqcn) : self
Parameters
- $fieldFqcn : string
Return values
selfsetFormattedValue()
public
setFormattedValue(mixed $value) : self
Parameters
- $value : mixed
Return values
selfsetFormType()
public
setFormType(string $formTypeFqcn) : self
Parameters
- $formTypeFqcn : string
Return values
selfsetFormTypeOption()
public
setFormTypeOption(string $optionName, mixed $optionValue) : self
Parameters
- $optionName : string
-
You can use "dot" notation to set nested options (e.g. 'attr.class')
- $optionValue : mixed
Return values
selfsetFormTypeOptionIfNotSet()
public
setFormTypeOptionIfNotSet(string $optionName, mixed $optionValue) : self
Parameters
- $optionName : string
-
You can use "dot" notation to set nested options (e.g. 'attr.class')
- $optionValue : mixed
Return values
selfsetFormTypeOptions()
public
setFormTypeOptions(array<string|int, mixed> $options) : self
Parameters
- $options : array<string|int, mixed>
Return values
selfsetHelp()
public
setHelp(TranslatableInterface|string $help) : self
Parameters
- $help : TranslatableInterface|string
Return values
selfsetLabel()
public
setLabel(TranslatableInterface|string|false|null $label) : self
Parameters
- $label : TranslatableInterface|string|false|null
Return values
selfsetPermission()
public
setPermission(string $permission) : self
Parameters
- $permission : string
Return values
selfsetProperty()
public
setProperty(string $propertyName) : self
Parameters
- $propertyName : string
Return values
selfsetRequired()
public
setRequired(bool $isRequired) : self
Parameters
- $isRequired : bool
Return values
selfsetSortable()
public
setSortable(bool $isSortable) : self
Parameters
- $isSortable : bool
Return values
selfsetTemplateName()
public
setTemplateName(string $name) : self
Parameters
- $name : string
Return values
selfsetTemplatePath()
public
setTemplatePath(string $path) : self
Parameters
- $path : string
Return values
selfsetTextAlign()
public
setTextAlign(string $textAlign) : self
Parameters
- $textAlign : string
-
It can be 'left', 'center' or 'right'
Return values
selfsetTranslatableChoices()
When the contents of the choices use translatable objects, you can't use the setChoices() method because PHP doesn't allow using objects as array keys.
public
setTranslatableChoices(mixed $choiceGenerator) : self
Given choices must follow the opposite of the format used in Symfony Forms: ['submitted_value' => t('Label visible to users'), ...].
Parameters
- $choiceGenerator : mixed
Return values
selfsetTranslationParameters()
public
setTranslationParameters(array<string|int, mixed> $parameters) : self
Parameters
- $parameters : array<string|int, mixed>
Return values
selfsetValue()
public
setValue(mixed $value) : self
Parameters
- $value : mixed
Return values
selfsetVirtual()
public
setVirtual(bool $isVirtual) : self
Parameters
- $isVirtual : bool
Return values
self__construct()
private
__construct() : mixed