Closed CSRGH27 closed 2 years ago
How the image is uploaded?
I use Easy Admin 3 in this project, so I use a collectionField with a nested form (ImageType).
here my controller:
<?php
namespace App\Controller\Admin;
use App\Entity\Housing;
use App\Form\ImageType;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class HousingCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Housing::class;
}
public function configureFields(string $pageName): iterable
{
return [
AssociationField::new ('owner')->hideOnForm(),
NumberField::new ('superficie')->setLabel('Superficie du bien'),
TextField::new ('address')->setLabel('Adresse du bien'),
NumberField::new ('rooms')->setLabel('Nombre de pièces'),
BooleanField::new ('parking')->setLabel('Parking ou garage'),
BooleanField::new ('pool')->setLabel('Piscine'),
BooleanField::new ('climatisation')->setLabel('Climatisation'),
BooleanField::new ('balcony')->setLabel('Balcon'),
BooleanField::new ('garden')->setLabel('Jardin'),
CollectionField::new ('images')
->setEntryType(ImageType::class)
->onlyOnForms()
->setLabel('Vos images'),
];
}
}
and my custom form :
<?php
namespace App\Form;
use App\Entity\Image;
use Symfony\Component\Form\AbstractType;
use Vich\UploaderBundle\Form\Type\VichFileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('imageFile', VichFileType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Image::class,
]);
}
}
Does it work without easyadmin?
I don't know if I have to try.
Take your time and try. If it works, ask support to easyadmin. Otherwise, feel free to open another issue.
Bug Report
8.1.12
Summary
I can't save my images because the image_name field is null .
Current behavior
Every time I validate my form I get a db constraint violation for the image_name field which is empty "An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image_name' cannot be null"
How to reproduce
my vich_uploader.yaml:
my image entity
Expected behavior
I would like my images to be saved with automatic naming
Thank you for your help !