8000 [Form] DRYed ChoiceType · symfony/symfony@8321593 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8321593

Browse files
committed
[Form] DRYed ChoiceType
1 parent 0753cee commit 8321593

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,23 @@ private function addSubFields(FormBuilder $builder, array $choiceViews, array $o
190190
if (is_array($choiceView)) {
191191
// Flatten groups
192192
$this->addSubFields($builder, $choiceView, $options);
193-
} elseif ($options['multiple']) {
194-
$builder->add((string) $i, 'checkbox', array(
195-
'value' => $choiceView->getValue(),
196-
'label' => $choiceView->getLabel(),
197-
// The user can check 0 or more checkboxes. If required
198-
// is true, he is required to check all of them.
199-
'required' => false,
200-
'translation_domain' => $options['translation_domain'],
201-
));
202193
} else {
203-
$builder->add((string) $i, 'radio', array(
194+
$choiceOpts = array(
204195
'value' => $choiceView->getValue(),
205196
'label' => $choiceView->getLabel(),
206197
'translation_domain' => $options['translation_domain'],
207-
));
198+
);
199+
200+
if ($options['multiple']) {
201+
$choiceType = 'checkbox';
202+
// The user can check 0 or more checkboxes. If required
203+
// is true, he is required to check all of them.
204+
$choiceOpts['required'] = false;
205+
} else {
206+
$choiceType = 'radio';
207+
}
208+
209+
$builder->add((string) $i, $choiceType, $choiceOpts);
208210
}
209211
}
210212
}

0 commit comments

Comments
 (0)
0