mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
person: fix altname denormalisation
This commit is contained in:
parent
bcdddcde9b
commit
49da5fe060
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
* PersonAltName.
|
||||
@ -34,6 +35,7 @@ class PersonAltName
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="key", type="string", length=255)
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $key;
|
||||
|
||||
@ -41,6 +43,7 @@ class PersonAltName
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="label", type="text")
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $label;
|
||||
|
||||
|
@ -138,10 +138,14 @@ class PersonJsonNormalizer implements
|
||||
|
||||
case 'altNames':
|
||||
foreach($data[$item] as $altName){
|
||||
$object = $this->denormalizer->denormalize($altName, PersonAltName::class, $format, $context);
|
||||
dump($object); //TODO not working
|
||||
if ($object instanceof PersonAltName) {
|
||||
$person->addAltName($object);
|
||||
$oldAltName = $person->getAltNames()->filter(function (PersonAltName $n) use ($altName) { return $n->getKey() === $altName['key']; })->first();
|
||||
if (false === $oldAltName) {
|
||||
$newAltName = new PersonAltName();
|
||||
$newAltName->setKey($altName['key']);
|
||||
$newAltName->setLabel($altName['label']);
|
||||
$person->addAltName($newAltName);
|
||||
} else {
|
||||
$oldAltName->setLabel($altName['label']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user