mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Fix nested forms problems with select2 FormTypes in issue 641 and 649
Select2UserLocationType.php is called in another context: UserController call UserCurrentLocationType which instanciate new Select2UserLocationType.php FormType
This commit is contained in:
@@ -15,7 +15,6 @@ use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class Select2SocialActionType extends AbstractType
|
||||
@@ -27,33 +26,25 @@ class Select2SocialActionType extends AbstractType
|
||||
$this->actionRender = $actionRender;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('social_actions', EntityType::class, [
|
||||
'class' => SocialAction::class,
|
||||
'choice_label' => function (SocialAction $sa) {
|
||||
return $this->actionRender->renderString($sa, []);
|
||||
},
|
||||
'placeholder' => 'Pick a social action',
|
||||
'required' => false,
|
||||
'label' => $options['label'],
|
||||
'label_attr' => $options['label_attr'],
|
||||
'multiple' => $options['multiple'],
|
||||
'attr' => ['class' => 'select2'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('label', 'Social actions')
|
||||
->setDefault('label_attr', [])
|
||||
->setDefault('multiple', false)
|
||||
->setDefaults([
|
||||
'class' => SocialAction::class,
|
||||
'choice_label' => function (SocialAction $sa) {
|
||||
return $this->actionRender->renderString($sa, []);
|
||||
},
|
||||
'placeholder' => 'Pick a social action',
|
||||
'required' => false,
|
||||
'attr' => ['class' => 'select2'],
|
||||
'label' => 'Social actions',
|
||||
'multiple' => false,
|
||||
])
|
||||
->setAllowedTypes('multiple', ['bool']);
|
||||
}
|
||||
|
||||
public function getBlockPrefix(): string
|
||||
public function getParent(): string
|
||||
{
|
||||
return 'select2_social_action_type';
|
||||
return EntityType::class;
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class Select2SocialIssueType extends AbstractType
|
||||
@@ -27,33 +26,25 @@ class Select2SocialIssueType extends AbstractType
|
||||
$this->issueRender = $issueRender;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('social_issues', EntityType::class, [
|
||||
'class' => SocialIssue::class,
|
||||
'choice_label' => function (SocialIssue $si) {
|
||||
return $this->issueRender->renderString($si, []);
|
||||
},
|
||||
'placeholder' => 'Pick a social issue',
|
||||
'required' => false,
|
||||
'label' => $options['label'],
|
||||
'label_attr' => $options['label_attr'],
|
||||
'multiple' => $options['multiple'],
|
||||
'attr' => ['class' => 'select2'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('label', 'Social issues')
|
||||
->setDefault('label_attr', [])
|
||||
->setDefault('multiple', false)
|
||||
->setDefaults([
|
||||
'class' => SocialIssue::class,
|
||||
'choice_label' => function (SocialIssue $si) {
|
||||
return $this->issueRender->renderString($si, []);
|
||||
},
|
||||
'placeholder' => 'Pick a social issue',
|
||||
'required' => false,
|
||||
'attr' => ['class' => 'select2'],
|
||||
'label' => 'Social issues',
|
||||
'multiple' => false,
|
||||
])
|
||||
->setAllowedTypes('multiple', ['bool']);
|
||||
}
|
||||
|
||||
public function getBlockPrefix(): string
|
||||
public function getParent(): string
|
||||
{
|
||||
return 'select2_social_issue_type';
|
||||
return EntityType::class;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user