From 25e7f4413b2777955314cc674baee1d3c3fb0b87 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 21 Oct 2009 02:23:14 +0000 Subject: [PATCH] BUGFIX Ensure that FileIFrameField gets the proper class, this could be a subclass of File instead MINOR Make use of dataClass() in FileIFrameField instead of calling the same has_one() method in multiple places (from r82175) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89715 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/FileIFrameField.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/forms/FileIFrameField.php b/forms/FileIFrameField.php index 0473ddf05..741b31409 100755 --- a/forms/FileIFrameField.php +++ b/forms/FileIFrameField.php @@ -16,6 +16,19 @@ class FileIFrameField extends FileField { 'DeleteFileForm' ); + /** + * The data class that this field is editing. + * @return string Class name + */ + public function dataClass() { + if($this->form && $this->form->getRecord()) { + $class = $this->form->getRecord()->has_one($this->Name()); + return ($class) ? $class : 'File'; + } else { + return 'File'; + } + } + /** * @return string */ @@ -58,7 +71,7 @@ class FileIFrameField extends FileField { * @return File|null */ public function AttachedFile() { - return $this->form->getRecord()->has_one($this->Name()) ? $this->form->getRecord()->{$this->Name()}() : null; + return $this->form->getRecord() ? $this->form->getRecord()->{$this->Name()}() : null; } /** @@ -92,11 +105,11 @@ class FileIFrameField extends FileField { $fileSources = array(); - if(singleton('File')->canCreate()) { + if(singleton($this->dataClass())->canCreate()) { $fileSources["new//$uploadFile"] = new FileField('Upload', ''); } - $fileSources["existing//$selectFile"] = new TreeDropdownField('ExistingFile', '', 'File'); + $fileSources["existing//$selectFile"] = new TreeDropdownField('ExistingFile', '', $this->dataClass()); return new Form ( $this, @@ -123,11 +136,7 @@ class FileIFrameField extends FileField { return; } - if($this->form->getRecord()->has_one($this->Name())) { - $desiredClass = $this->form->getRecord()->has_one($this->Name()); - } else { - $desiredClass = 'File'; - } + $desiredClass = $this->dataClass(); // upload a new file if($data['FileSource'] == 'new') {