Search code examples
symfonydropzoneeasyadminsymfonyux

symfony easyadmin dropzone field


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);

Solution

  • 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