From c5228ea0241b5b6025a53baa2974ac8292ddc343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Maa=C3=9F?= Date: Sat, 2 Feb 2013 13:42:54 +0100 Subject: [PATCH] NEW: Subclasses of Image are now instantiated and used, according to the has_one definition of the corresponding DataObject --- code/GridFieldBulkImageUpload_Request.php | 26 ++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index 32bcec0..3a7f34d 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -110,7 +110,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { $imageField = null; foreach( $recordHasOneFields as $field => $type ) { - if ( $type == 'Image' ) { + if($type == 'Image' || is_subclass_of($type, 'Image')) { $imageField = $field . 'ID'; break; } @@ -118,7 +118,27 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { return $imageField; } - + + /** + * Returns the classname of the first has_one image-relation of the managed DataObject + * + * @return string + */ + private function getDefaultRecordImageClass() + { + $recordClass = $this->gridField->list->dataClass; + $recordHasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED); + + foreach($recordHasOneFields as $field => $type) + { + if($type == 'Image' || is_subclass_of($type, 'Image')) + { + return $type; + } + } + return null; + } + /** * * @param type $recordID @@ -283,7 +303,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { // Process the uploaded file if (!$return['error']) { - $fileObject = Object::create('Image'); + $fileObject = Object::create($this->getDefaultRecordImageClass()); // Get the uploaded file into a new file object. try {