Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Subsites: limit asset folder selection in content editor


Reply


3 Posts   1153 Views

Avatar
db3l

Community Member, 1 Post

2 March 2011 at 12:32pm

After some experimentation a while back, I returned to the subsites module this week (using the latest repository version) and was pleasantly surprised to find support for assigning ownership to asset folders to particular subsites.

However, the one place it doesn't seem to entirely be applied is when attaching images in the content editor (tinymce), with the attachment right pane pop-up window - specifically the drop-down folder selection and default folder. Now, selecting a folder the subsite has no access to does filter out entries (though uploading to such a folder appears to hang rather than yield an error), but I'd rather such folders were hidden in the first place, and that the default folder was one owned by the subsite (rather than the top level folder). In my setup, each subsite will have a single asset folder.

Can anyone provide a hint as to where I might start tweaking the code for this. I'm willing to make local modifications but am having a little trouble identifying just where I want to be working in the code.

Thanks for any pointers.

-- David

Avatar
camfindlay

Forum Moderator, 188 Posts

23 June 2011 at 8:04pm

Another issue I have also been having with subsites in the content editor, exact same problem, glad I'm not alone there...

I have a project I'm using subsites for and have been desperately trying to solve this, no luck yet but I did manage to track down down the files where most of the action happens.

They are:
/sapphire/forms/HtmlEditorField.php - HtmlEditorField_Toolbar class and ImageForm() Method

/sapphire/javascript/HtmlEditorField.js

I tried a bunch of stuff but couldn't get it to filter for the current subsite,
I was hoping that the FileSubsites.php decorator might have sorted this out? I think the TreeDropdownField using ajax might be dropping the SubsiteID but I'm not too sure (still learning the inner workings of sapphire core!).

Have you had any leads?

Avatar
camfindlay

Forum Moderator, 188 Posts

27 July 2011 at 3:25pm

Ok after a bit of tinkering and hacking of the core I have managed to get a fix for this issue!

The fix is also able to be applied outside of the core, so no custom sapphire or hack up required!

This is how I solved this:

1. Create an extension file to the "HtmlEditorField_Toolbar" class (call this what ever you like) drop that in your mysite/code folder.

/mysite/code/CustomHtmlEditorField_Toolbar.php

<?php
class CustomHtmlEditorField_Toolbar extends HtmlEditorField_Toolbar {....

2. Override the "ImageForm" method, copy the entire method from the extended class with the following change at the beginning of the
method:

function ImageForm() {

if(class_exists('Subsite')){
$folders = DataObject::get("Folder", "ParentID = 0 AND SubsiteID=".Subsite::currentSubsiteID());
$map = $folders->toDropDownMap('ID', 'Title');   
$tree = new TreeDropdownField('FolderID', _t('HtmlEditorField.FOLDER', 'Folder'), $map);
} else {
$tree = new TreeDropdownField('FolderID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder');
}
      
$fields = new FieldSet(...

3. The above gets a list of folders specific only to the current set Subsite, the only draw back is it only give you the top level folders instead of the entire tree (but at the time this was an acceptable trade off to get this to work!).

4. A little further into the ImageForm method replace "new TreeDropdownField('FolderID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder')" with "$tree" which will build the TreeDropdownField if the Subsites Module is installed from the values we pulled in step 2.

5. Now in your _config.php add the following line:

Object::useCustomClass('HtmlEditorField_Toolbar', 'CustomHtmlEditorField_Toolbar');

This will replace any use of the HtmlEditorField_Toolbar class with your custom version which now overrides the ImageForm method.

6. Upload, run your dev/build to make sure everything is in place and working.

7. Start viewing the image folders relating only to the current Subsite!

If anyone can improve on this please post your code! Perhaps this my become a pull request for the Subsite module at a later point.