Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3873' into develop
Browse files Browse the repository at this point in the history
Forward port #3873
  • Loading branch information
weierophinney committed Mar 11, 2013
2 parents 9b1f67e + 6360cc2 commit 4f195c9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/Zend/Form/Element/Collection.php
Expand Up @@ -477,6 +477,12 @@ public function extract()
$targetElement = clone $this->targetElement;
$targetElement->object = $value;
$values[$key] = $targetElement->extract();
if ($this->has($key)) {
$fieldset = $this->get($key);
if ($fieldset instanceof Fieldset && $fieldset->allowObjectBinding($value)) {
$fieldset->setObject($value);
}
}
}
}

Expand Down
38 changes: 38 additions & 0 deletions tests/ZendTest/Form/Element/CollectionTest.php
Expand Up @@ -284,6 +284,44 @@ public function testExtractFromObjectDoesntTouchOriginalObject()
$this->assertSame($originalObjectHash,$objectAfterExtractHash);
}

public function testDoesNotCreateNewObjects()
{
$form = new \Zend\Form\Form();
$form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods());
$this->productFieldset->setUseAsBaseFieldset(true);
$form->add($this->productFieldset);

$product = new Product();
$product->setName("foo");
$product->setPrice(42);
$cat1 = new \ZendTest\Form\TestAsset\Entity\Category();
$cat1->setName("bar");
$cat2 = new \ZendTest\Form\TestAsset\Entity\Category();
$cat2->setName("bar2");

$product->setCategories(array($cat1,$cat2));

$form->bind($product);

$form->setData(
array("product"=>
array(
"name" => "franz",
"price" => 13,
"categories" => array(
array("name" => "sepp"),
array("name" => "herbert")
)
)
)
);
$form->isValid();

$categories = $product->getCategories();
$this->assertSame($categories[0], $cat1);
$this->assertSame($categories[1], $cat2);
}

public function testExtractDefaultIsEmptyArray()
{
$collection = $this->form->get('fieldsets');
Expand Down

0 comments on commit 4f195c9

Please sign in to comment.