#1 May 19, 2013 5:11pm

asiral
Member
Registered: May 18, 2013
Posts: 43

Possible File Browser Field Type

Hi,

How can I create a field type that uses the file browser triggered by the hyperlink button in the RTE? It would be nice to link to documents and other files that are managed centrally through the file browser as opposed to uploading them each time they are needed in a module outside of an RTE.

I'm assuming I can get started from the php ajax files for the file browser and the php files for the upload field but hopefully you can provide some guidance to help me navigate a solution quicker.

Thanks,
Michael

Offline

#2 May 20, 2013 9:43am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Possible File Browser Field Type

It shouldn't be too hard to create a file browser field type. What you'll want to do is just create a hidden (or maybe a visible disabled text input) and then a link to open the file browser.

You'll want to hook the link that opens the file browser to call BigTreeFileManager.tinyMCEOpen("key_of_field","","file");

That should make it so that when the person chooses a file it will write that value back to the input field (obviously you'll want to switch key_of_field to be whatever the resource's key is).

I know the method name is kind of dumb. The regular formOpen method is setup specifically for image choosing so it's not currently as versatile. The tinyMCEOpen method is taking what TinyMCE throws at it so the parameters are a bit strange as well.

Hopefully that should be all you need, let me know how it goes!

Offline

#3 May 27, 2013 7:21am

asiral
Member
Registered: May 18, 2013
Posts: 43

Re: Possible File Browser Field Type

That function requires a fourth parameter, 'win' being the window object and then finds the first 'form' element in the document. It seems this is appropriate for TinyMCE (I imagine the window for linking a file in TinyMCE is passed as the fourth parameter) but the field is actually in the second form element on the admin page.

So, in the view for the custom field, I actually created a new method for BigTreeFileManager and am using it successfully.  Still going to mess with displaying the field value, etc. Ideally, my goal will be to create a field that the editor can choose to link to a file or a page and then browse the files or the pages (which is the next big hurdle).

Offline

#4 May 27, 2013 9:42am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Possible File Browser Field Type

TinyMCE and it's crazy quirks, ugh. Glad you got a workaround in place. We're hoping to expand on the file manager in BigTree 4.1 and making it easier to work with in other field types will definitely be on the upgrade list.

Offline

#5 May 28, 2013 9:49am

asiral
Member
Registered: May 18, 2013
Posts: 43

Re: Possible File Browser Field Type

Actually, I chose a slightly different route.

I also wanted a "link" field type that could choose pages from a "page manager" which represented the full tree of pages.  So I created a field which has two buttons to the right, similar to the "Upload" field type.  One is to choose a resource such as an image or PDF through the BigTreeFileManager, the other is to open my custom BigTreePageBrowser.

It was really straightforward to repurpose your existing code for the page browser.  It's quite long because it involves the draw and process scripts as well as the JavaScript and styles, but I'd be happy to share here or elsewhere for consideration to include in future releases (this is coincidentally how I discovered the "getNaturalNavigationByParent" bug).  This way, I have a field type that can ensure links to resources and pages, when used individually in data fields, are stored in a maintainable fashion and editors can choose to link to either with just one field.

Very excited about it.  Now I just have to figure the best way to include it in the array of items field.  :-)

Offline

#6 May 28, 2013 9:54am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Possible File Browser Field Type

That sounds awesome! Array of Items is still a pain point for us as well, hoping we can get that field type a bit more flexible in the 4.1 release. We plan to release a portion of bigtreecms.org for sharing of modules / field types sometime this summer and it would be great if you shared your work! I'm not sure if you can upload files on the forums or not, but you could always link out from here as well.

Offline

#7 May 28, 2013 12:27pm

asiral
Member
Registered: May 18, 2013
Posts: 43

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.