mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-07 23:34:58 +00:00
add docgen:normalization for relation
This commit is contained in:
@@ -16,7 +16,6 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Chill\PersonBundle\Repository\Relationships\RelationRepository;
|
||||
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||
use DateTimeInterface;
|
||||
@@ -107,8 +106,8 @@ class PersonDocGenNormalizer implements
|
||||
array_merge($context, [
|
||||
'docgen:person:with-household' => false,
|
||||
'docgen:person:with-relation' => false,
|
||||
'docgen:relationship:counterpart' => $person
|
||||
])
|
||||
'docgen:relationship:counterpart' => $person,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Relationships\Relation;
|
||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||
use Symfony\Component\Serializer\Exception\CircularReferenceException;
|
||||
use Symfony\Component\Serializer\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Serializer\Exception\LogicException;
|
||||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
class RelationshipDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
@@ -29,7 +32,7 @@ class RelationshipDocGenNormalizer implements ContextAwareNormalizerInterface, N
|
||||
/**
|
||||
* @param Relationship $relation
|
||||
*/
|
||||
public function normalize($relation, string $format = null, array $context = [])
|
||||
public function normalize($relation, ?string $format = null, array $context = [])
|
||||
{
|
||||
$counterpart = $context['docgen:relationship:counterpart'] ?? null;
|
||||
$contextPerson = array_merge($context, [
|
||||
@@ -46,8 +49,8 @@ class RelationshipDocGenNormalizer implements ContextAwareNormalizerInterface, N
|
||||
|
||||
if (null === $relation) {
|
||||
return [
|
||||
"id" => "",
|
||||
"fromPerson" => $nullPerson = $this->normalizer->normalize(null, $format, $contextPerson),
|
||||
'id' => '',
|
||||
'fromPerson' => $nullPerson = $this->normalizer->normalize(null, $format, $contextPerson),
|
||||
'toPerson' => $nullPerson,
|
||||
'opposite' => $nullPerson,
|
||||
'text' => '',
|
||||
@@ -75,13 +78,13 @@ class RelationshipDocGenNormalizer implements ContextAwareNormalizerInterface, N
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, string $format = null, array $context = [])
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = [])
|
||||
{
|
||||
if ('docgen' !== $format) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data instanceof Relationship || (null === $data
|
||||
&& ($context['docgen:expects'] ?? null) === Relationship::class);
|
||||
&& Relationship::class === ($context['docgen:expects'] ?? null));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user