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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Extending/Overriding FileIFrameField (or any other Sapphire class)


Go to End


4 Posts   1187 Views

Avatar
Wilson

Community Member, 63 Posts

16 December 2010 at 8:18am

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

Avatar
Wilson

Community Member, 63 Posts

17 December 2010 at 4:35am

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!!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 December 2010 at 4:55am

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

Avatar
Wilson

Community Member, 63 Posts

17 December 2010 at 4:59am

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!