artgris / FileManagerBundle

FileManager is a simple Multilingual File Manager Bundle for Symfony
MIT License
175 stars 90 forks source link

How to chose file in tinyMCE? #107

Open mariia-moiseienko opened 2 years ago

mariia-moiseienko commented 2 years ago

I have tinyMCE 6.2 in my project. How to chose file?

My code js:

function myFileBrowser(callback, value, meta) {
  var type = meta.filetype;
  var cmsURL = "file_manager/?conf=tiny";
  if (cmsURL.indexOf("?") < 0) {
    cmsURL = cmsURL + "?type=" + type;
  }
  else {
    cmsURL = cmsURL + "&type=" + type;
  }
  var windowManagerCSS = '<style type="text/css">' +
      '.tox-dialog {max-width: 100%!important; width:97.5%!important; overflow: hidden; height:95%!important; border-radius:0.25em;}' +
      '.tox-dialog__body { padding: 0!important; }' +
      '.tox-dialog__body-content > div { height: 100%; overflow:hidden}' +
      '</style> ';
  window.tinymceCallBackURL = '';
  window.tinymceWindowManager = tinymce.activeEditor.windowManager;
  tinymceWindowManager.open({
    title: 'Menedżer plików',
    url: cmsURL,
    body: {
      type: 'panel',
      items: [{
        type: 'htmlpanel',
        html: windowManagerCSS + `<iframe src="/file_manager/?conf=tiny&type=${type}" style="width:100%; height:500px" id="filemanager"></iframe>`
      }]
    },
    buttons: [],
    onClose: function () {
      if (tinymceCallBackURL != '')
        callback(tinymceCallBackURL, {}); //to set selected file path
    }
  });
}

TinyMCE init: tinymce.init({ selector: '.tinymce', file_picker_callback: myFileBrowser, .......... }

image

And I can't choose an image by click or by check:

image

The selected file path is empty. Can you help me?

artgris commented 2 years ago

Hi @mariia-moiseienko,

you need to add module=tiny in cmsURL :

var cmsURL = "file_manager/?module=tiny&conf=tiny";

and replace: html: windowManagerCSS + '<iframe src="/file_manager/?conf=tiny&type=${type}" ... :thinking: with: html: windowManagerCSS + '<iframe src="' + cmsURL ...

artgris commented 2 years ago

https://github.com/artgris/FileManagerBundle/blob/master/Resources/doc/tutorials/integrate-tinymce.md