[Form] DRYed ChoiceType

This commit is contained in:
Helmer Aaviksoo 2012-02-02 21:39:13 +02:00
parent 0753cee11a
commit 8321593c85

View File

@ -190,21 +190,23 @@ class ChoiceType extends AbstractType
if (is_array($choiceView)) { if (is_array($choiceView)) {
// Flatten groups // Flatten groups
$this->addSubFields($builder, $choiceView, $options); $this->addSubFields($builder, $choiceView, $options);
} elseif ($options['multiple']) { } else {
$builder->add((string) $i, 'checkbox', array( $choiceOpts = array(
'value' => $choiceView->getValue(), 'value' => $choiceView->getValue(),
'label' => $choiceView->getLabel(), 'label' => $choiceView->getLabel(),
'translation_domain' => $options['translation_domain'],
);
if ($options['multiple']) {
$choiceType = 'checkbox';
// The user can check 0 or more checkboxes. If required // The user can check 0 or more checkboxes. If required
// is true, he is required to check all of them. // is true, he is required to check all of them.
'required' => false, $choiceOpts['required'] = false;
'translation_domain' => $options['translation_domain'], } else {
)); $choiceType = 'radio';
} else { }
$builder->add((string) $i, 'radio', array(
'value' => $choiceView->getValue(), $builder->add((string) $i, $choiceType, $choiceOpts);
'label' => $choiceView->getLabel(),
'translation_domain' => $options['translation_domain'],
));
} }
} }
} }