I want to use ElFinder as my file manager in my Symfony project. I followed the doc on GitHub. In my routes.yaml:
elfinder:
resource: '@FMElfinderBundle/Resources/config/routing.yaml'
security.yaml
- { path: ^/efconnect, role: [ROLE_USER] }
- { path: ^/elfinder, role: [ROLE_USER] }
And finally on fm_elfinder.yaml
fm_elfinder:
instances:
default:
locale: '%locale%' # defaults to current request locale
editor: ckeditor # other options are tinymce, tinymce4, fm_tinymce, form, simple, custom
connector:
roots:
uploads:
driver: LocalFileSystem
path: uploads
upload_max_size: 2M
Then I added it on a Admin element on Sonata, like this: protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('Contenu')
->add('published', CheckboxType::class, ['required' => false, 'label' => 'Publier'])
->add('title', TextType::class, ['required' => true, 'label' => 'Titre'])
->add('textLink', TextType::class, ['required' => true, 'label' => 'Texte du lien'])
->add('media', ElFinderType::class, array(
'label' => 'Photo',
'enable' => true,
'required' => true,
'instance' => 'default',
'attr' => array('class' => 'form-control')
)
)
->end();
}
Then I go on Sonata Admin, and when I try to add an image, a window open, I added an jpeg but then when i click on it, nothing seems to happen. Like, I can select it but my window stay open and my field doesn't fill up with the name of the image. Thanks for your help.
Ok I got it to work on my easyadmin forms. This is the easyAdmin 2 configuration :
(I copied the
vendor/helios-ag/fm-elfinder-bundle/src/Form/Type/ElFinderType.php
file toApp\Form\ElFinderType.php
. This is not required).I set the fm_elfinder connector to simple :
Next I copied two of the template files from the bundle to my
templates\bundles
directory :This first one contains the fields and the JavaScript needed to fill them in. I added a
Add
button. This will open the elfinder, once an image gets selected this button becomes hidden and aRemove
button will be added.Next is the ElFinder window :
The main thing added here to make it work is the
getFileCallback
function :This now works fine for my single image field and does not affect the CKEditor integration.