helios-ag / FMElfinderBundle

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

Find file by Hash in controller(backend) #341

Closed klodoma closed 5 years ago

klodoma commented 5 years ago

This is how I get the file Path in the backend for a specific hash in Symfony3, (I use version ~6 of this bundle) "helios-ag/fm-elfinder-bundle": "~6",

// we are in a controller action here

        /** @var ElFinderLoader $loader */
        $loader = $this->get('fm_elfinder.loader');
        $loader->initBridge('default');
        $file = $loader->decode($hash);

where $hash is the hash of the file.

Now, I have upgraded to Symfony 4 and it doesn't work anymore due to a protected method error, which probably is a bug in the library. In Symfony4 I use "helios-ag/fm-elfinder-bundle": "^9.1",

I am not sure if this is the correct way to do it, but is there any other way to get the filePath from a hash?

screenshot_228

helios-ag commented 5 years ago

Correct, i have dropped ElFinderPHP in favor to elfinder library itself, and decode function in original repo is protected

klodoma commented 5 years ago

I found a workaround, I am currently overriding the loader class. You could replace ->decode with ->getPath(), or better, add a getPath() function

This is what I currently did:

/**
 * Class MyElFinderLoader.
 */
class MyElFinderLoader extends ElFinderLoader
{
    /**
     * Decode path from hash.
     *
     * @param string $hash
     *
     * @return string
     **/
    public function decode($hash)
    {
        $volume = $this->bridge->getVolume($hash);

        /** @var $volume \elFinderVolumeDriver */
        return (!empty($volume)) ? $volume->getPath($hash) : false;
    }
}

and use this loader in the services.yaml

    myElfinderLoader:
        class: MappsBundle\Services\MyElFinderLoader
        arguments: ["@fm_elfinder.configurator"]