more attempts to make dynamic form work

This commit is contained in:
2022-08-17 16:03:58 +02:00
parent 01f6eb1a8f
commit 5060906591
3 changed files with 32 additions and 24 deletions

View File

@@ -6,9 +6,11 @@ use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
@@ -26,17 +28,26 @@ class SocialWorkTypeFilter implements FilterInterface
private TranslatableStringHelper $translatableStringHelper;
public function __construct(SocialActionRender $socialActionRender, TranslatableStringHelper $translatableStringHelper)
private SocialActionRepository $socialActionRepository;
public function __construct
(
SocialActionRender $socialActionRender,
TranslatableStringHelper $translatableStringHelper,
SocialActionRepository $socialActionRepository
)
{
$this->socialActionRender = $socialActionRender;
$this->translatableStringHelper = $translatableStringHelper;
$this->socialActionRepository = $socialActionRepository;
}
public function buildForm(FormBuilderInterface $builder)
{
$socialActions = $this->socialActionRepository->findAll();
$builder->add('actionType', EntityType::class, [
'class' => SocialAction::class,
$builder->add('actionType', ChoiceType::class, [
'choices' => $socialActions,
'choice_label' => function (SocialAction $sa) {
return $this->socialActionRender->renderString($sa, []);
},
@@ -48,8 +59,7 @@ class SocialWorkTypeFilter implements FilterInterface
$goals = null === $actionType ? [] : $actionType->getGoals();
$form->add('goal', EntityType::class, [
'class' => Goal::class,
$form->add('goal', ChoiceType::class, [
'placeholder' => '',
'choices' => $goals,
'choice_label' => function (Goal $g) {
@@ -58,22 +68,18 @@ class SocialWorkTypeFilter implements FilterInterface
]);
};
$builder->addEventListener(FormEvents::POST_SUBMIT, function (PostSubmitEvent $event) use ($refreshGoals) {
dump($event);
$form = $event->getForm();
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($refreshGoals) {
$data = $event->getData();
dump($data);
$refreshGoals($form, $data);
$refreshGoals($event->getForm(), $data);
});
$builder->get('actionType')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($refreshGoals) {
$actionType = $event->getForm()->getData();
dump('after submit listener');
dump($actionType);
$refreshGoals($event->getForm()->getParent(), $actionType);
}
);
@@ -129,4 +135,4 @@ class SocialWorkTypeFilter implements FilterInterface
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}
}