Skip to content

Commit

Permalink
Merge pull request #682 from pulse00/modeltype
Browse files Browse the repository at this point in the history
Fixed choice_list for ModelType
  • Loading branch information
rande committed Apr 13, 2012
2 parents 39e7a53 + 5371787 commit dae8526
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Form/Type/ModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Sonata\AdminBundle\Form\Type;

use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\AbstractType;
Expand Down Expand Up @@ -52,15 +53,18 @@ public function getDefaultOptions()
'parent' => 'choice',
'preferred_choices' => array(),
'choice_list' => function (Options $options, $previousValue) {
if (null === $previousValue) {
return new ModelChoiceList(
$options['model_manager'],
$options['class'],
$options['property'],
$options['query'],
$options['choices']
);
if ($previousValue instanceof ChoiceListInterface
&& count($choices = $previousValue->getChoices())) {
return $choices;
}

return new ModelChoiceList(
$options['model_manager'],
$options['class'],
$options['property'],
$options['query'],
$options['choices']
);
}
);

Expand Down

0 comments on commit dae8526

Please sign in to comment.