Person document generation: clean build Admin form + add household and relations groups

This commit is contained in:
nobohan 2022-03-01 15:51:34 +01:00
parent a187bac7b0
commit 88e9a96e0e

View File

@ -24,8 +24,6 @@ use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -92,30 +90,6 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
public function buildAdminForm(FormBuilderInterface $builder): void
{
$builder
->add('mainPerson', CheckboxType::class, [
'required' => false,
'label' => 'docgen.Ask for main person',
])
->add('mainPersonLabel', TextType::class, [
'label' => 'main person label',
'required' => true,
])
// ->add('person1', CheckboxType::class, [
// 'required' => false,
// 'label' => 'docgen.Ask for person 1',
// ])
// ->add('person1Label', TextType::class, [
// 'label' => 'person 1 label',
// 'required' => true,
// ])
// ->add('person2', CheckboxType::class, [
// 'required' => false,
// 'label' => 'docgen.Ask for person 2',
// ])
// ->add('person2Label', TextType::class, [
// 'label' => 'person 2 label',
// 'required' => true,
// ])
->add('category', EntityType::class, [
'placeholder' => 'Choose a document category',
'class' => 'ChillDocStoreBundle:DocumentCategory',
@ -135,24 +109,13 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
if (!$entity instanceof Person) {
throw new UnexpectedTypeException($entity, Person::class);
}
$options = $template->getOptions();
$data = [];
$data = array_merge($data, $this->baseContextData->getData());
$data['person'] = $this->normalizer->normalize($entity, 'docgen', [
'docgen:expects' => Person::class,
'groups' => 'docgen:read'
'groups' => ['docgen:read', 'docgen:person:with-household', 'docgen:person:with-relations']
]);
// foreach (['mainPerson', 'person1', 'person2'] as $k) {
// if ($options[$k]) {
// $data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [
// 'docgen:expects' => Person::class,
// 'groups' => 'docgen:read',
// 'docgen:person:with-household' => true,
// 'docgen:person:with-relations' => true,
// ]);
// }
// }
return $data;
}