Skip to content

Instantly share code, notes, and snippets.

@docteurklein
Last active December 15, 2015 23:59
Show Gist options
  • Save docteurklein/5344071 to your computer and use it in GitHub Desktop.
Save docteurklein/5344071 to your computer and use it in GitHub Desktop.
Form ChoiceType: entityChoiceList vs ObjectChoiceList
<?php
//$this->getUser()->getCandidates() returns an array of EUser entities
$entityChoiceListForm = $this->createForm('choice', null, array(
'choice_list' => new EntityChoiceList(
$this->get('doctrine')->getManager(),
'SSCoreBundle:EUser',
'name',
null,
$this->getUser()->getCandidates()
),
));
$objectChoiceListForm = $this->createForm('choice', null, array(
'choice_list' => new ObjectChoiceList($this->getUser()->getCandidates(), 'name'),
));
$objectChoiceListForm->bind(array('choice' => 0)); // select the first item of the list
$entityChoiceListForm->bind(array('choice' => 0)); // select the first item of the list
assertEquals($entityChoiceListForm->getData(), $objectChoiceListForm->getData(), 'form data should be the same'); // failure
// The `ObjectChoiceList` fails to retrieve the element of index: 0
@docteurklein
Copy link
Author

@bschussek any idea why this behavior, or if I do something wrong ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment