Skip to content

Commit

Permalink
[Form] CollectionType now checks for data_class parameter instead of …
Browse files Browse the repository at this point in the history
…only class.
  • Loading branch information
marc.weistroff committed Jul 21, 2011
1 parent 0327beb commit 2e024f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Expand Up @@ -30,8 +30,10 @@ public function buildForm(FormBuilder $builder, array $options)
$builder->setAttribute('prototype', $prototype);
}

if ($options['class']) {
$listener = new ObjectFactoryListener($options['class']);
$dataClass = isset($options['options']['data_class']) ? $options['options']['data_class'] : null;
if ($dataClass || $options['class']) {
$class = $dataClass ? $dataClass : $options['class'];
$listener = new ObjectFactoryListener($class);
$builder->addEventSubscriber($listener);
}

Expand Down
Expand Up @@ -153,14 +153,7 @@ public function testObjectsAreCreated()
))
;

$data = array(
array(
'last_name' => 'Foo'
),
array(
'last_name' => 'Bar'
),
);
$data = array(array('last_name' => 'Foo'), array('last_name' => 'Bar'));
$form->bind($data);
$bound = $form->getData();
$this->assertEquals(2, count($bound));
Expand All @@ -169,4 +162,20 @@ public function testObjectsAreCreated()
$this->assertEquals('Foo', $bound[0]->getLastName());
$this->assertEquals('Bar', $bound[1]->getLastName());
}

public function testObjectsAreCreatedWithDataClassOption()
{
$form = $this->factory
->create('collection', null, array(
'type' => new AuthorType(),
'allow_add' => true,
'options' => array('data_class' => 'Symfony\Tests\Component\Form\Fixtures\Author')
))
;

$data = array(array('last_name' => 'Foo'), array('last_name' => 'Bar'));
$form->bind($data);
$bound = $form->getData();
$this->assertInstanceOf('Symfony\Tests\Component\Form\Fixtures\Author', $bound[0]);
}
}

0 comments on commit 2e024f8

Please sign in to comment.