From e87b76b3055223ba3b16216c52c089cecb3dda50 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Sun, 13 Jan 2008 22:51:03 +0000 Subject: [PATCH] #892 - Error attaching an existing folder to an ImageField git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47941 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Image.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/model/Image.php b/core/model/Image.php index 6daef47a7..0c33eaa21 100755 --- a/core/model/Image.php +++ b/core/model/Image.php @@ -645,7 +645,7 @@ class Image_Uploader extends Controller { } $owner = DataObject::get_by_id($data['Class'], $data['ID']); $fieldName = $data['Field'] . 'ID'; - + if($data['ImageSource'] == 'existing') { if(!$data['ExistingFile']) { // No image has been selected @@ -658,6 +658,14 @@ class Image_Uploader extends Controller { // Edit the class name, if applicable $existingFile = DataObject::get_by_id("File", $data['ExistingFile']); $desiredClass = $owner->has_one($data['Field']); + + // Unless specifically asked, we don't want the user to be able + // to select a folder + if(is_a($existingFile, 'Folder') && $desiredClass != 'Folder') { + Director::redirectBack(); + return; + } + if(!is_a($existingFile, $desiredClass)) { $existingFile->ClassName = $desiredClass; $existingFile->write();