Skip to content

Commit

Permalink
[Doctrine] Cleanup and move loader into its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei authored and stof committed Dec 19, 2011
1 parent 7646a5b commit 3c81b62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Expand Up @@ -52,7 +52,7 @@ public function transform($collection)

foreach ($collection as $entity) {
// identify choices by their collection key
$key = array_search($entity, $availableEntities);
$key = array_search($entity, $availableEntities, true);
$array[] = $key;
}
} else {
Expand Down
25 changes: 20 additions & 5 deletions src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php
Expand Up @@ -22,6 +22,9 @@

class EntityType extends AbstractType
{
/**
* @var ManagerRegistry
*/
protected $registry;

public function __construct(ManagerRegistry $registry)
Expand Down Expand Up @@ -58,11 +61,7 @@ public function getDefaultOptions(array $options)
if (!isset($options['choice_list'])) {
$manager = $this->registry->getManager($options['em']);
if (isset($options['query_builder'])) {
$options['loader'] = new ORMQueryBuilderLoader(
$options['query_builder'],
$manager,
$options['class']
);
$options['loader'] = $this->getLoader($manager, $options);
}

$defaultOptions['choice_list'] = new EntityChoiceList(
Expand All @@ -78,6 +77,22 @@ public function getDefaultOptions(array $options)
return $defaultOptions;
}

/**
* Return the default loader object.
*
* @param ObjectManager
* @param array $options
* @return ORMQueryBuilderLoader
*/
protected function getLoader($manager, $options)
{
return new ORMQueryBuilderLoader(
$options['query_builder'],
$manager,
$options['class']
);
}

public function getParent(array $options)
{
return 'choice';
Expand Down

0 comments on commit 3c81b62

Please sign in to comment.