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
This commit is contained in:
Sean Harvey 2009-10-21 02:23:14 +00:00
parent 325f4b6b6f
commit 25e7f4413b

View File

@ -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') {