[alt names] add alt names on person creation form

This commit is contained in:
2020-02-03 12:47:55 +01:00
parent 289afcdd0c
commit 5154039182
8 changed files with 85 additions and 27 deletions

View File

@@ -3,6 +3,7 @@
namespace Chill\PersonBundle\Form\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Chill\PersonBundle\Entity\PersonAltName;
@@ -44,7 +45,15 @@ class PersonAltNameDataMapper implements DataMapperInterface
public function mapFormsToData($forms, &$viewData)
{
$mapIndexToKey = [];
foreach ($viewData->getIterator() as $key => $altName) {
if (is_array($viewData)) {
$dataIterator = $viewData;
} else {
$dataIterator = $viewData instanceof ArrayCollection ?
$viewData->toArray() : $viewData->getIterator();
}
foreach ($dataIterator as $key => $altName) {
/** @var PersonAltName $altName */
$mapIndexToKey[$altName->getKey()] = $key;
}
@@ -64,7 +73,12 @@ class PersonAltNameDataMapper implements DataMapperInterface
->setKey($key)
->setLabel($form->getData())
;
$viewData->add($altName);
if (is_array($viewData)) {
$viewData[] = $altName;
} else {
$viewData->add($altName);
}
}
}
}