docgen normalization for relation

This commit is contained in:
2021-12-09 12:44:41 +01:00
parent 5d24bd4d11
commit 24a404964b
11 changed files with 396 additions and 24 deletions

View File

@@ -16,6 +16,8 @@ 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;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
@@ -34,16 +36,20 @@ class PersonDocGenNormalizer implements
private PersonRender $personRender;
private RelationshipRepository $relationshipRepository;
private TranslatableStringHelper $translatableStringHelper;
private TranslatorInterface $translator;
public function __construct(
PersonRender $personRender,
RelationshipRepository $relationshipRepository,
TranslatorInterface $translator,
TranslatableStringHelper $translatableStringHelper
) {
$this->personRender = $personRender;
$this->relationshipRepository = $relationshipRepository;
$this->translator = $translator;
$this->translatableStringHelper = $translatableStringHelper;
}
@@ -94,6 +100,18 @@ class PersonDocGenNormalizer implements
);
}
if ($context['docgen:person:with-relations'] ?? false) {
$data['relations'] = $this->normalizer->normalize(
$this->relationshipRepository->findByPerson($person),
$format,
array_merge($context, [
'docgen:person:with-household' => false,
'docgen:person:with-relation' => false,
'docgen:relationship:counterpart' => $person
])
);
}
return $data;
}