Permalink
Browse files

Fix bug with not preserving the original entity objects in a Collecti…

…on upon validating the form
  • Loading branch information...
1 parent 9a8e3f3 commit 2bb68d74f05f0a2b10e7d76bd86d49daed40d132 @sjuvonen sjuvonen committed Mar 19, 2013
Showing with 24 additions and 0 deletions.
  1. +24 −0 library/Zend/Form/Element/Collection.php
View
24 library/Zend/Form/Element/Collection.php
@@ -233,6 +233,8 @@ public function populateValues($data)
)
);
}
+
+ $this->replaceTemplateObjects();
}
/**
@@ -536,4 +538,26 @@ protected function createTemplateElement()
return $elementOrFieldset;
}
+
+ /**
+ * Replaces the default template object of a sub element with the corresponding
+ * real entity so that all properties are preserved.
+ *
+ * @return void
+ */
+ protected function replaceTemplateObjects()
+ {
+ $fieldsets = $this->getFieldsets();
+
+ if (!count($fieldsets) || !$this->object) {
+ return;
+ }
+
+ foreach ($fieldsets as $fieldset) {
+ $i = $fieldset->getName();
+ if (isset($this->object[$i])) {
+ $fieldset->setObject($this->object[$i]);
+ }
+ }
+ }
}

0 comments on commit 2bb68d7

Please sign in to comment.