helios-ag / FMElfinderBundle

:file_folder: ElFinderBundle provides ElFinder integration with TinyMCE, CKEditor, Summernote editors
MIT License
275 stars 128 forks source link

ElFinderType in EasyAdmin 4.x (with Symfony 6.x) form shows only a text field #472

Closed Baloobear closed 2 years ago

Baloobear commented 2 years ago

Hello everyone.

Describe the bug

When I try to integrate a form field of the type ElFinderType in my EasyAdmin crud controller I only get a simple text field without any function.

Even trying to integrate the infos related to https://stackoverflow.com/questions/64480120/using-elfinder-on-symfony-i-cant-select-images or #406 (incl. overwriting the templates and converting the given infos to the updated EasyAdmin 3.x/4.x configuration) does not help in any way. It also seems that the widget template (neither the original one or the own in templates/bundles/FMElFinderBundle/Form) seems not to be used.

To Reproduce

Here's the code I'm using:

CrudController

// ProjectCrudController.php
// ...
public function configureFields(string $pageName): iterable
{
    // ...
    yield Field::new('introImage', 'Intro Image')
        ->setFormType(ElFinderType::class)
        ->setFormTypeOptions([
            'instance' => 'projects_default',
            'enable' => true,
        ])
        ->onlyOnForms()
    ;
    // ...
}

_fmelfinder.yaml

fm_elfinder:
    instances:
        projects_default:
            locale: 'de'
            editor: form
            visible_mime_types: ['image/png', 'image/jpg', 'image/jpeg']
            connector:
                roots:
                    projects:
                        driver: LocalFileSystem
                        path: images/projects
                        upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
                        upload_max_size: 5M

Additional context

Used packages/libs:

Any help is appreciated.

Kind regards, Dennis

helios-ag commented 2 years ago

hi @Baloobear, it would be nice if you check what printed in browser console.

Baloobear commented 2 years ago

Hi @helios-ag,

after there was no browser console output I did a quick check with a standard (non EasyAdmin) form including a field of the type ElFinder::class which works as expected so I took a deeper look into my config.

Finally I got the reason why the widget template hasn't been loaded: the widget form type template must be added to the CRUD controller (similar to the EasyAdmin 2 config).

I did it with the following code in my CrudController:

public function configureCrud(Crud $crud): Crud
{
    return $crud
        // ...
        ->addFormTheme('@FMElfinder/Form/elfinder_widget.html.twig')
    ;
}

With this done the form renders the correct ElFinder form widget and one can start from this point to change the widget template to fit the personal needs etc.

So maybe you can extend the docs with a section for EasyAdmin 3.x/4.x with this info.

Greetings, Dennis

helios-ag commented 2 years ago

@Baloobear thanks for sharing your solution! Appreciate that!