[Form] fix failing tests for remove call on an objectCollection

This commit is contained in:
jaugustin 2012-05-08 21:09:09 +02:00 committed by Bernhard Schussek
parent 076a104e86
commit 9215c4478f

View File

@ -489,6 +489,7 @@ class PropertyPath implements \IteratorAggregate
// Collection with matching adder/remover in $objectOrArray
if ($addMethod && $removeMethod) {
$itemsToAdd = is_object($value) ? clone $value : $value;
$itemToRemove = array();
$previousValue = $this->readProperty($objectOrArray, $currentIndex);
if (is_array($previousValue) || $previousValue instanceof Traversable) {
@ -503,11 +504,15 @@ class PropertyPath implements \IteratorAggregate
}
}
// Item not found, remove
$objectOrArray->$removeMethod($previousItem);
// Item not found, add to remove list
$itemToRemove[] = $previousItem;
}
}
foreach ($itemToRemove as $item) {
$objectOrArray->$removeMethod($item);
}
foreach ($itemsToAdd as $item) {
$objectOrArray->$addMethod($item);
}