add form to doc generation and custom form to admin template configuration

This commit is contained in:
2021-12-01 23:00:02 +01:00
parent 7719d2b073
commit 475b40e896
15 changed files with 484 additions and 108 deletions

View File

@@ -18,6 +18,7 @@ use Chill\DocStoreBundle\Form\StoredObjectType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -33,30 +34,34 @@ class DocGeneratorTemplateType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$contexts = array_flip(array_map(static function (DocGeneratorContextInterface $c) {
return $c->getName();
}, $this->contextManager->getContexts()));
/** @var DocGeneratorTemplate $template */
$template = $options['data'];
$context = $this->contextManager->getContextByKey($template->getContext());
$builder
->add('name', TranslatableStringFormType::class, [
'label' => 'Nom',
])
->add('context', ChoiceType::class, [
'required' => true,
'label' => 'Context',
'choices' => $contexts,
])
->add('entities', ChoiceType::class, [
'multiple' => true,
'choices' => [
'AccompanyingPeriod' => 'Chill\PersonBundle\Entity\AccompanyingPeriod',
'SocialWork\SocialAction' => 'Chill\PersonBundle\Entity\SocialWork\SocialAction',
'AccompanyingPeriod\AccompanyingPeriodWorkEvaluation' => AccompanyingPeriodWorkEvaluation::class,
], ])
->add('description')
->add('file', StoredObjectType::class, [
'error_bubbling' => true,
]);
])
;
if ($context->hasAdminForm()) {
$sub = $builder
->create('options', null, ['compound' => true])
->addModelTransformer(new CallbackTransformer(
function (array $data) use ($context) {
return $context->adminFormTransform($data);
},
function (array $data) use ($context) {
return $context->adminFormReverseTransform($data);
}
));
$context->buildAdminForm($sub);
$builder->add($sub);
}
}
public function configureOptions(OptionsResolver $resolver)