helios-ag / FMElfinderBundle

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

Initial elfinder screen doesn't show the files when using custom adapter (flysystem) #510

Closed BackNot closed 1 year ago

BackNot commented 1 year ago

I try to implement elfinder with my own custom adapter. I installed this https://github.com/barryvdh/elfinder-flysystem-driver. I inherited from FilesystemAdapter and implemented only one method (so far) in my custom adapter - listContents. The problem is that elfinder does not initially show my files, but when I search for them in the search bar they appear. Also the "info" button shows that there are 2 files. Here is my adapter logic:

class SharepointAdapter implements FilesystemAdapter
// ....
 public function listContents(string $path, bool $deep): iterable
    {
        $path = "/tmp/asd.txt";
        $path2 = "/tmp/dsa.txt";
        return [
            FileAttributes::class::fromArray([
            StorageAttributes::ATTRIBUTE_TYPE => StorageAttributes::TYPE_FILE,
            StorageAttributes::ATTRIBUTE_PATH => $path,
            StorageAttributes::ATTRIBUTE_LAST_MODIFIED => filemtime($path),
            StorageAttributes::ATTRIBUTE_FILE_SIZE => filesize($path),
            StorageAttributes::ATTRIBUTE_MIME_TYPE =>  mime_content_type($path),
            'visibility' => 'public',
        ]),
           FileAttributes::class::fromArray([
                StorageAttributes::ATTRIBUTE_TYPE => StorageAttributes::TYPE_FILE,
                StorageAttributes::ATTRIBUTE_PATH => $path2,
                StorageAttributes::ATTRIBUTE_LAST_MODIFIED => filemtime($path2),
                StorageAttributes::ATTRIBUTE_FILE_SIZE => filesize($path2),
                StorageAttributes::ATTRIBUTE_MIME_TYPE => mime_content_type($path2),
                'visibility' => 'public'
            ])
        ];
    }

fm_elfinder.yaml:

fm_elfinder:
    #assets_path: / # default is /assets, this is where css/js elfinder files are
    instances:
        default:
            editor: ckeditor # other options are tinymce, tinymce4, fm_tinymce, form, simple, custom
            relative_path: false #default true, will produce absolute urls to specified file(s)
            #editor_template: custom template for your editor # default null
            #path_prefix: / # for setting custom assets path prefix, useful for non vhost configurations, i.e. http://127.0.0.1/mysite/
            #fullscreen: true|false # default is true, applies to simple and ckeditor editors
            #theme: smoothness # jquery theme, default is 'smoothness'
            #visible_mime_types: ['image/png', 'image/jpg', 'image/jpeg'] # only show these mime types, defaults to show all
            connector:
                #debug: true|false # defaults to false
                roots:       # at least one root must be defined, defines root filemanager directories
                    uploads:
                        driver: Flysystem
                        flysystem:
                            type: custom # !set type to custom, it will tell bundle to use custom driver
                            adapter_service: 'local_adapter' # select previously configured adapter service
                            options:
                        upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
                        upload_deny: ['all']
                        upload_max_size: 2M # also file upload sizes restricted in php.ini
                        #attributes: example of setting attributes permission
                        #    - { pattern: '/(.*?)/', read: true, write: false, locked: true }
Screenshot 2023-06-26 at 17 07 51 Screenshot 2023-06-26 at 17 07 41 Screenshot 2023-06-26 at 17 10 55

It seems that the files are sent correctly in the initial response:

Screenshot 2023-06-26 at 17 09 14

I can't find any errors in the log.

BackNot commented 1 year ago

It turns out I had to add "path" variable to the fm_elfinder file. It works like this:

                   uploads:
                        driver: Flysystem
                        path: tmp
                        flysystem:
                            type: custom # !set type to custom, it will tell bundle to use custom driver
                            adapter_service: 'local_adapter' # select previously configured adapter service