Jump to:

10929 Posts in 2613 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Extending/Overriding FileIFrameField (or any other Sapphire class)

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 821 Views
  • Wilson
    Avatar
    Community Member
    63 Posts

    Extending/Overriding FileIFrameField (or any other Sapphire class) Link to this post

    Hi,

    I've been struggling with extending or overriding a Sapphire class, FileIFrameField. After a few hours of research, I got on IRC and confirmed with 'simon_w' that this isn't possible.

    However, it occurred to me today, would it be possible to put the entire FileIFrameField.php in my 'mysite' code directory, nested the same as Sapphire and override it. Similar to Zend.

    I'll give it a shot, but wanted to post in case anyone had any further thoughts/advice.

    Thanks,
    Wilson

  • Wilson
    Avatar
    Community Member
    63 Posts

    Re: Extending/Overriding FileIFrameField (or any other Sapphire class) Link to this post

    I got pretty far with this last night, but ran up against a _construct() error.

    //mysite/code/CustomFileIFrameField.php
    class CustomFileIFrameField extends FileIFrameField{
    public function EditForm ...
    }

    //mysite/_config.php
    Director::addRules(100, array(
    'admin/EditForm/$URLSegment/$Action/$ID/$OtherID' => 'CustomFileIFrameField '
    ));

    It was definitely routing the URL to the custom class but then failing with:

    'first parameter of Field _construct() not found'

    I'm thinking that may be easy to overcome with an init() or child _construct(), but I ran out of time.

    Still would love any feedback. I wonder if perhaps the URL in the Director::addRules isn't right?

    Thanks!!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Extending/Overriding FileIFrameField (or any other Sapphire class) Link to this post

    What exactly are you trying to customize? You'd probably have an easier time with an Uploadify field.

  • Wilson
    Avatar
    Community Member
    63 Posts

    Re: Extending/Overriding FileIFrameField (or any other Sapphire class) Link to this post

    Hi UncleCheese. Thanks for the reply.

    I'm actually only trying to set the root folder in the TreeDropDownField around line 138, so that the User only sees their subsite (our project has about 400 subsites). This is my customization:

    138 $fileSources["existing//$selectFile"] = new TreeDropdownField('ExistingFile', '', 'File');

    139 //custom
    140 $sessionId = Session::get('SubsiteID');
    141 if ($sessionId) {
    142 $rootAssetFolder = DataObject::get_one("File","Filename = 'assets/$sessionId/'");
    143 if ($rootAssetFolder) {
    144 $fileSources["existing//$selectFile"]->setTreeBaseID($rootAssetFolder->ID);
    145 }
    146 }

    Perhaps it would be fixed/enabled in the subsites module one day, but my client needed the project up ASAP.

    I was hoping to just override the EditForm method so I could keep sapphire loading via SVN externals.

    Thanks for any advice!

    821 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.