mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 11:03:50 +00:00
add form to doc generation and custom form to admin template configuration
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user