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, Ed, biapar, Willr, Ingo, swaiba

Extending/Overriding FileIFrameField (or any other Sapphire class)

Go to End

4 Posts   1115 Views


Community Member, 63 Posts

16 December 2010 at 8:18am


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.



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.

class CustomFileIFrameField extends FileIFrameField{
public function EditForm ...

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?



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.


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!