symfony easyadmin dropzone field

586 views Asked by At

is there a way in symfony easyadmin I can configureFields of type symfony ux Dropzone ??

I used this method but when I drag drop, the preview image does not show ,any help

yield Field::new('imageFile')
->onlyOnForms()
->setFormType(DropzoneType::class);
2

There are 2 answers

0
Ismael Lastlevel On BEST ANSWER

I've figured out a way to achieve this;

  1. you have to register symfony-ux dropzone form theme within twig:
twig:
    paths: 
        '%kernel.project_dir%/vendor/symfony/ux-dropzone/templates': CustomDropzoneNamespace
  1. add the form theme when using the DropzoneType (or globally if you want):
yield Field::new('imageFile')
    ->setFormType(DropzoneType::class,)
    ->addFormTheme('@CustomDropzoneNamespace/form_theme.html.twig')
  1. you have to make sure that the stimulux-ux is loaded properly within easyadmin:
public function configureAssets(): Assets
    {
        return Assets::new()
            ->addWebpackEncoreEntry('backend');
    }

where "backend" is a webpack entry that loads the stimulus js controller

0
Ju_ On

Just add these lines in your DashboardController extends AbstractDashboardController Where 'app' is your webpack entry's name

    public function configureAssets(): Assets
    {
        return parent::configureAssets()
            ->addWebpackEncoreEntry('app')
        ;
    }

    public function configureCrud(): Crud
    {
        return parent::configureCrud()
            ->addFormTheme('@Dropzone/form_theme.html.twig')
            ;
    }