Jump to:

10929 Posts in 2613 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Subsites: limit asset folder selection in content editor

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1061 Views
  • db3l
    Avatar
    Community Member
    1 Post

    Subsites: limit asset folder selection in content editor Link to this post

    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

  • camfindlay
    Avatar
    Forum Moderator
    146 Posts

    Re: Subsites: limit asset folder selection in content editor Link to this post

    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?

  • camfindlay
    Avatar
    Forum Moderator
    146 Posts

    Re: Subsites: limit asset folder selection in content editor Link to this post

    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.

    1061 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.