Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Form] DRYed ChoiceType

  • Loading branch information...
commit 8321593c8504b0daaf9f383a9864d963289562a4 1 parent 0753cee
@helmer helmer authored
Showing with 13 additions and 11 deletions.
  1. +13 −11 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
View
24 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
@@ -190,21 +190,23 @@ private function addSubFields(FormBuilder $builder, array $choiceViews, array $o
if (is_array($choiceView)) {
// Flatten groups
$this->addSubFields($builder, $choiceView, $options);
- } elseif ($options['multiple']) {
- $builder->add((string) $i, 'checkbox', array(
- 'value' => $choiceView->getValue(),
- 'label' => $choiceView->getLabel(),
- // 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(
+ $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.
+ $choiceOpts['required'] = false;
+ } else {
+ $choiceType = 'radio';
+ }
+
+ $builder->add((string) $i, $choiceType, $choiceOpts);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.