Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // within the controller it works like this:
- $defaultData = ['books' => $booksVal];
- $myForm = $this->createFormBuilder($defaultData)
- ->add('books', ChoiceType::class, [
- 'choices' => $defaultData,
- 'choice_label' => function ($value) { return $value; },
- // however, integrated in a CustomType it doesn't:
- $form = $this->createForm(
- /* type */ CustomeType::class,
- /* data */ ['books' => $booksVal]);
- // here is the CustomType:
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- $builder
- ->add('books', ChoiceType::class, [
- 'choices' => /* what I'm supposed to write here? */ ,
- 'choice_label' => function ($value) { return $value; },
- 'multiple' => true,
- 'expanded' => true
- // The Symfony docu says, but how do I get $group within my CustomType?
- // @link: https://symfony.com/doc/master/reference/forms/types/entity.html ('Using Choices')
- $builder->add('users', EntityType::class, array(
- 'class' => 'AppBundle:User',
- 'choices' => $group->getUsers(), // how can this be achieved?
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement