Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed choice_list for ModelType #682

Merged
merged 2 commits into from
Apr 13, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not respect the CS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it go in 1 line instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to phpcs this is CS compliant now.

return $choices;
}

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

Expand Down