2

I’m converting an add-on from EE 2 to EE 3. It uses $.ee_filebrowser.add_trigger. As far as I can that still exists but I get a console error:

Uncaught TypeError: Cannot read property 'dialog' of undefined

I can’t quite figure out what to do. I’ve tried to dicipher it in the minified code but I can’t quote figure it out. Can anyone point me in the right direction?

2
  • I'm also having this issue. did you ever figure out a fix or did you perhaps file this as a bug with EllisLab?
    – Ben Croker
    Jan 20 '16 at 10:54
  • I had to stop working on the add-on I was working on so I never did figure it out. I’ll be returning to that add-on in the next couple of weeks so if it’s still an issue, hopefully we can get it sorted out.
    – TJ Draper
    Jan 20 '16 at 14:53
1

Had time to circle back around to this and finish up my add-on. I don’t think the FilePicker service was documented when I started the question, but it certainly is now:

https://docs.expressionengine.com/latest/development/services/filepicker.html

But I needed to make specific links in my add-on open with a specific directory but I would not necessarily know before hand. I needed to make the FilePicker links available to my template so I could select them based on the upload directory. So I did this:

// Load the FilePicker
$filePicker = ee('CP/FilePicker')->make();

// Class that gets EE's upload directories
$uploadDirectories = new UploadDirectories();

// Add each directories upload link to array
$modalLinks = array();
foreach ($uploadDirectories as $dir) {
    $modalLinks[$dir['id']] = array(
        'link' => $filePicker->setDirectories($dir['id'])
            ->getLink(lang('field_type_add_image'))
            ->setAttribute('class', 'btn action js-ansel-add-image')
            ->asThumbs()
            ->enableFilters()
            ->enableUploads()
            ->render(),
        'hiddenLink' => $filePicker->setDirectories($dir['id'])
            ->getLink(lang('field_type_add_image'))
            ->setAttribute('class', 'btn action js-ansel-add-image js-hide')
            ->asThumbs()
            ->enableFilters()
            ->enableUploads()
            ->render()
    );
}

I make that available to my template. Now I can select the correct button from the array based on the directory ID.

Then on the Javascript side:

$(.js-ansel-add-image).FilePicker({
    callback: function(file, references) {
        // Close the modal
        references.modal.find('.m-close').click();

        // Do stuff
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.