[Form] DRYed ChoiceType

This commit is contained in:
Helmer Aaviksoo 2012-02-02 21:39:13 +02:00
parent 0753cee11a
commit 8321593c85
1 changed files with 13 additions and 11 deletions

View File

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