'Expected argument of type "App\Entity\Personnes", "array" given at property path "professeurs"

I have an exception on my "handlerequest" that tells me "Expected argument of type "App\Entity\Personnes", "array" given at property path "professeurs"." I've been stuck on it for several days now.

My entity user :

#[ORM\ManyToMany(targetEntity: Reunion::class, mappedBy: 'professeurs')]
private $reunions;

public function __construct()
{
    $this->evenements = new ArrayCollection();
    $this->participations = new ArrayCollection();
    $this->reunions = new ArrayCollection();
}

My meeting entity :

#[ORM\ManyToMany(targetEntity: Personnes::class, inversedBy: 'reunions')]
private $professeurs;

public function __construct()
{
    $this->professeurs = new ArrayCollection();
    $this->sujets = new ArrayCollection();
}

My controller :

#[Route('/professeur/reunion/create', name: 'create_reunion')]
public function create_reunion(Request $request, EntityManagerInterface $em): Response
{
    $reunion = new Reunion;
    $form = $this->createForm(ReunionType::class, $reunion);
    $form->handleRequest($request);

    if ($form->isSubmitted()) {
        $reunion->addProfesseur($this->getUser());
        $em->persist($reunion);
        $em->flush();
    }

    return $this->render('reunion/create.html.twig', [
        'formView' => $form->createView()
    ]);
}

My form :

class ReunionType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
    $builder
        ->add('dateReunion', DateTimeType::class)
        ->add('objet', TextType::class, [
            'attr' => [
                'placeholder' => 'Objet de la réunion'
            ]
        ])
        ->add('professeurs', CollectionType::class, [
            'label' => "Ajouter des professeurs",
            'entry_type' => ProfType::class,
            'by_reference' => false,
            "allow_add" => true,
            "allow_delete" => true
        ]);
}

public function configureOptions(OptionsResolver $resolver): void
{
    // $resolver->setDefaults([
    //     'data_class' => Reunion::class,
    // ]);
}
}

And for the 'entry_type' :

class ProfType extends AbstractType{

public function __construct(protected PersonnesRepository $pr)
{
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
    $builder
        ->add('personnes', EntityType::class, [
            'label' => false,
            'class' => Personnes::class,
            'placeholder' => "-- Choisir un professeur --",
            'attr' => [
                'class' => "form-select"
            ],
            'choices' => $this->pr->findByRole('PROF'),
            'choice_label' =>  function (Personnes $personnes) {
                return strtoupper($personnes->getNom()) . " " . $personnes->getPrenom();
            }
        ]);
}

public function configureOptions(OptionsResolver $resolver): void
{
    // $resolver->setDefaults([
    //     'data_class' => Personnes::class,
    // ]);
}
}

The exception

Normaly my "professeurs" collection can recieve 1 or more entity.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source