How to map the formModel and the formType in a multi step form Symfony 4

I want to make a simple multistep form Symfony 4 based on several entities in my database.
I got a Prestation entity that are linked to Programming languages.One programming language has one prestation but any prestation can contain many programming languages.ManyToOne.
And Many programming can make many catalog and vice versa.

In my specific form step 2, I did that :

class CatalogType extends AbstractType
{
    private $prestationRepository;

    public function __construct(PrestationRepository $prestationRepository)
    {
        $this->prestationRepository = $prestationRepository;
    }
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $prestations = $this->prestationRepository->findAll();
        foreach ($prestations as $p) {
            $builder->add('prestations_'.$p->getId(), CollectionType::class, [
                'entry_type' => PrestationType::class,
                'entry_options' => ['label' => false, 'idPrestation' => $p->getId()],
            ]);
        }
   }

   public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => CatalogueFormModel::class,
            'csrf_protection' => false,
        ]);
    }
}

Then, my formModel :

class CatalogFormModel
{
  /*  @var PrestationFormModel[]|Collection
   */
   public  $prestations;
}

In PrestationFormModel :

class PrestationFormModel 
{
   /* @var ProgrammingLanguageFormModel[]
   */
   public $programmingLanguages;
}

At the end, ProgrammingLanguageFormModel :

class ProgrammingFormModel 
{

   public $name;
   public $rate;
   public $total; 

}

When I trying to display my twig, Symfony reclaim $prestations_1, $prestations_2 ….
Can you please help me for resolve that ?

For the view thats my picture result of form tab :
enter image description here

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *