8000 [Form] Improve `ChoiceType` CS by HeahDude · Pull Request #17351 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Form] Improve ChoiceType CS #17351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ method::
// a callback to return the label for a given choice
// if a placeholder is used, its empty value (null) may be passed but
// its label is defined by its own "placeholder" option
'choice_label' => function(?Category $category) {
'choice_label' => function (?Category $category) {
return $category ? strtoupper($category->getName()) : '';
},
// returns the html attributes for each option input (may be radio/checkbox)
'choice_attr' => function(?Category $category) {
'choice_attr' => function (?Category $category) {
return $category ? ['class' => 'category_'.strtolower($category->getName())] : [];
},
// every option can use a string property path or any callable that get
// passed each choice as argument, but it may not be needed
'group_by' => function() {
'group_by' => function () {
// randomly assign things into 2 groups
return rand(0, 1) == 1 ? 'Group A' : 'Group B';
},
// a callback to return whether a category is preferred
'preferred_choices' => function(?Category $category) {
'preferred_choices' => function (?Category $category) {
return $category && 100 < $category->getArticleCounts();
},
]);
Expand Down Expand Up @@ -190,7 +190,7 @@ if you want to take advantage of lazy loading::
// ...

$builder->add('constants', ChoiceType::class, [
'choice_loader' => new CallbackChoiceLoader(function() {
'choice_loader' => new CallbackChoiceLoader(function () {
return StaticClass::getConstants();
}),
]);
Expand Down
2 changes: 1 addition & 1 deletion reference/forms/types/options/choice_attr.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If an array, the keys of the ``choices`` array must be used as keys::
'No' => false,
'Maybe' => null,
],
'choice_attr' => function($choice, $key, $value) {
'choice_attr' => function ($choice, $key, $value) {
// adds a class like attending_yes, attending_no, etc
return ['class' => 'attending_'.strtolower($key)];
},
Expand Down
0