upthe field add an image does not appear in my form with vich

48 Views Asked by At

I want to be able to add several photos to a page of my blog

Maybe it's a silly error or not, but I can't add the 'selection image' with vich:

My Files class

use Vich\UploaderBundle\Mapping\Annotation as Vich;

#[ORM\Entity(repositoryClass: FilesRepository::class)]
#[Vich\Uploadable]
class Files
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

     // NOTE: This is not a mapped field of entity metadata, just a simple property.
     #[Vich\UploadableField(mapping: 'blog_images', fileNameProperty: 'imageName', size: 'imageSize')]
     private ?File $imageFile = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $imageName = null;

    #[ORM\Column]
    private ?int $imageSize = null;

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

    #[ORM\ManyToOne(targetEntity: Blog::class, inversedBy: 'blogs')]
    private $blogs = null;


    public function setImageFile(?File $imageFile = null): void
    {
        $this->imageFile = $imageFile;

        if (null !== $imageFile) {
            // It is required that at least one field changes if you are using doctrine
            // otherwise the event listeners won't be called and the file is lost
            $this->updatedAt = new \DateTimeImmutable();
        }
    }

    public function getImageFile(): ?File
    {
        return $this->imageFile;
    }

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

    public function getImageName(): ?string
    {
        return $this->imageName;
    }

    public function setImageName(?string $imageName): self
    {
        $this->imageName = $imageName;

        return $this;
    }

    public function getImageSize(): ?int
    {
        return $this->imageSize;
    }

    public function setImageSize(int $imageSize): self
    {
        $this->imageSize = $imageSize;

        return $this;
    }

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

    public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    public function getTattoos(): ?Tattoo
    {
        return $this->tattoos;
    }

    public function setTattoos(?Tattoo $tattoos): self
    {
        $this->tattoos = $tattoos;

        return $this;
    }


   
}

My Blog class:

 #[ORM\OneToMany(targetEntity: Files::class, mappedBy: "blog")]
    private Collection $blogs;

Anglais

In my blog form I added this (to call another form):

->add('images', CollectionType::class, [
            'entry_type' => FilesFormType::class,
        ])

And my FilesFormType:

class FilesFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('imageFile', VichImageType::class);
        ;
    }

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

But, for me, I must have the button that allows you to add an image, right? I just have a label with 'Image' written...

Thanks for your help

0

There are 0 best solutions below