Bonjour, J'ai un problème de edit de mon entité offers J'arrive à créer une nouvelle annonce avec une reference générée dans OffersRepository (repo) En éditant et en appliquant le formulaire dans la route offers/edit un li apprait avec le message de problème de typage suivant : This value should be of type array|IteratorAggregate.
J'ai donc débugé avec le profiler et trouvé que c'est le champ reference qui est en cause
This value should be of type array|IteratorAggregate.

#[Route('/{id}/edit', name: 'app_offers_edit', methods: ['GET', 'POST'])]
    public function edit(Request $request, Offers $offer, EntityManagerInterface $entityManager,PictureService $pictureService, OpeningHoursRepository $oh): Response
    {
        $form = $this->createForm(OffersType::class, $offer);
        $form->handleRequest($request);
        //$offer ->setOfferTitle('test');

        Debug::enable();
        if ($form->isSubmitted() && $form->isValid()) {

            //dd($offer);
            $offer->setModifiedAt(new \DateTimeImmutable());
            $images = $form->get('images')->getData();

            if (!empty($images)) {

                foreach ($images as $image) {
                    // Définir le dossier de destination
                    $folder = 'cars';

                    // Appel du Service PictureService.php
                    $file = $pictureService->add($image, $folder, 800, 600);

                    $img = new Images();
                    $img->setName($file);
                    $offer->addImage($img);
                }

                $entityManager->flush();

                return $this->redirectToRoute('app_offers_index', [], Response::HTTP_SEE_OTHER);
            }
            //dd($offer);

            foreach($images as $image){
                //définir le dossier de destination
                $folder = 'cars';

                //Appel du Service PictureService.php
                $file = $pictureService->add($image,$folder,800,600);

                $img = new Images();
                $img->setName($file);
                $offer->addImage($img);

            }

            $entityManager->persist($offer);
            $entityManager->flush();

            $this->addFlash("success","Annonce modifiée avec succès !");
            return $this->redirectToRoute('app_offers_index', [], Response::HTTP_SEE_OTHER);
        }

        return $this->render('offers/edit.html.twig', [
            'offer' => $offer,
            'form' => $form,
            'openingHours' => $oh->findAll(),
        ]);
    }

//OffersType.php

<> ShareMyCode.io
Ajouter un code
Connexion
Inscription
Voici votre URL de partage https://sharemycode.io/c/17c44bc (Cliquer pour copier)
Nom du fichier : Form Offers

<?php

namespace App\Form;

use App\Entity\Cars;
use App\Entity\Contacts;
use App\Entity\Offers;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Image;

class OffersType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            //->add('reference')
            ->add('offer_title')
            //->add('car', CarsType::class)
            ->add('car', EntityType::class, [
                'class' => Cars::class,
                'choice_label' => 'reference',
                'multiple' => false,
                'expanded' => false,
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('u')->orderBy('u.reference', 'DESC');
                },
                'choice_value' => 'id',
            ])
            ->add('images', FileType::class, [
                'label' => "Image(s) à Uploader",
                'multiple' => true,
                'mapped' => false,
                'required' => false,
                'constraints' => [
                    new All(
                        new Image([
                            'maxWidth' => 1280,
                            'maxWidthMessage' => 'L\'image doit faire {{ max_width }} pixels de large au maximum'
                        ])
                    )
                ]
            ])
        ;
    }

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

//Offers.php

<?php

namespace App\Entity;

use App\Repository\OffersRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: OffersRepository::class)]
//#[UniqueEntity(fields: ['reference'])]
#[UniqueEntity(fields: ['reference'],message: 'Ce titre ou reference existe déjà !')]
class Offers
{
    #[ORM\Id]
    #[ORM\GeneratedValue("CUSTOM")]
    #[Assert\Uuid]
    #[ORM\Column(type:"uuid", unique:true)]
    #[ORM\CustomIdGenerator("doctrine.uuid_generator")]

    private ?string $id = null;

    /**
     * @Assert\Unique(message="La valeur {{ value }}  est déjà dans la base.")
     */

    #[ORM\Column(length: 100)]
    private ?string $reference = null;

    #[ORM\Column(length: 100)]
    private ?string $offer_title = null;

    /*#[ORM\OneToOne(inversedBy: 'offer', cascade: ['persist', 'remove'])]
    #[ORM\JoinColumn(nullable: false)]
    private ?Cars $car = null;*/

    #[ORM\OneToMany(mappedBy: 'offer', targetEntity: Images::class, orphanRemoval: true,cascade: ["persist", "remove"])]
    private Collection $images;

    #[ORM\OneToMany(mappedBy: 'offer', targetEntity: Contacts::class, orphanRemoval: true)]
    private Collection $contacts;

    #[ORM\Column]
    private ?\DateTimeImmutable $created_at = null;

    #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $modified_at = null;

    #[ORM\JoinColumn]
    #[ORM\OneToOne(cascade: ['persist'])]
    private ?Cars $car = null;

    public function __construct()
    {
        $this->images = new ArrayCollection();
        $this->contacts = new ArrayCollection();
    }

    public function getId(): ?string
    {
        return $this->id;
    }

    public function getReference(): ?string
    {
        return $this->reference;
    }

    public function setReference(string $reference): self
    {
        $this->reference = $reference;

        return $this;
    }

    public function getOfferTitle(): ?string
    {
        return $this->offer_title;
    }

    public function setOfferTitle(string $offer_title): self
    {
        $this->offer_title = $offer_title;

        return $this;
    }

    /*public function getCarId(): ?Cars
    {
        return $this->car;
    }

    public function setCarId(Cars $car): self
    {
        $this->car = $car;

        return $this;
    }*/

    /**
     * @return Collection<int, Images>
     */
    public function getImages(): Collection
    {
        return $this->images;
    }

    public function addImage(Images $image): self
    {
        if (!$this->images->contains($image)) {
            $this->images[] = $image;
            $image->setOffer($this);
        }

        return $this;
    }

    public function removeImage(Images $image): self
    {
        if ($this->images->removeElement($image)) {
            // set the owning side to null (unless already changed)
            if ($image->getOffer() === $this) {
                $image->setOffer(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Contacts>
     */
    public function getContacts(): Collection
    {
        return $this->contacts;
    }

    public function addContact(Contacts $contact): self
    {
        if (!$this->contacts->contains($contact)) {
            $this->contacts->add($contact);
            $contact->setOffer($this);
        }

        return $this;
    }

    public function removeContact(Contacts $contact): self
    {
        if ($this->contacts->removeElement($contact)) {
            // set the owning side to null (unless already changed)
            if ($contact->getOffer() === $this) {
                $contact->setOffer(null);
            }
        }

        return $this;
    }

    public function getCreatedAt(): ?\DateTimeImmutable
    {
        return $this->created_at;
    }

    public function setCreatedAt(\DateTimeImmutable $created_at): self
    {
        $this->created_at = $created_at;

        return $this;
    }

    public function getModifiedAt(): ?\DateTimeInterface
    {
        return $this->modified_at;
    }

    public function setModifiedAt(?\DateTimeInterface $modified_at): self
    {
        $this->modified_at = $modified_at;

        return $this;
    }

    public function getCar(): ?Cars
    {
        return $this->car;
    }

    public function setCar(?Cars $car): self
    {
        $this->car = $car;

        return $this;
    }
}

Le générateur de réferences ainsi que l'uploadeur d'images ne sont pas en cause je pense ils fonctionnent d'ailleurs quand je crée une nouvelle annonce (offer)
c'est seulement à l'édition que je rencontre ce problème
au déboage il n'y a pas d'entrée dans la condition if ($form->isSubmitted() && $form->isValid())
sauriez vous m'éclairer ?

Aucune réponse