EasyAdmin 3 - CollectionField add form entryType options?
Asked Answered
C

1

6

in my CRUD Controller I have a CollectionField which has an entryType option referring to a formType

yield CollectionField::new('drinks', 'Boissons')
  ->setFormTypeOption('by_reference', false)
  ->setEntryType(CommandProductItemType::class);

CommandProductItemType

    public function buildForm(FormBuilderInterface $builder, array $options)
    {

        $builder
            ->add('product', EntityType::class, [
                'label' => 'Produit',
                'class' => Product::class,
                'choice_label' => 'namePrice',
            ])
            ->add('quantity', IntegerType::class, [
                'label' => 'Quantité',
                'attr' => [
                    'min' => 1
                ]
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => CommandProductItem::class,
            'category' => Category::class
        ]);
    }

How can I pass the category option to the CommandProductItemType from the CollectionField item ?

Collusion answered 22/6, 2021 at 10:36 Comment(0)
M
1

You have to edit entry_options option from CollectionType field:

yield CollectionField::new('drinks', 'Boissons')
  ->setFormTypeOption('entry_options', ['by_reference' => false])
  ->setEntryType(CommandProductItemType::class);
Marciano answered 12/6, 2023 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.