From c26fae6aaa38b236c654409ecd83416fabb648fa Mon Sep 17 00:00:00 2001 From: s-m Date: Sat, 2 Feb 2013 18:26:48 +0100 Subject: [PATCH] FIX: Forgot to include the classname that can be derived from the config-option 'imageFieldName'... --- code/GridFieldBulkImageUpload_Request.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index 5f0d3a6..2302e17 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -120,15 +120,23 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { } /** - * Returns the classname of the first has_one image-relation of the managed DataObject + * Returns the classname of the first has_one image-relation of the managed DataObject or the + * classname of the given fieldname * * @return string */ - private function getDefaultRecordImageClass() + private function getRecordImageClass() { $recordClass = $this->gridField->list->dataClass; $recordHasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED); + $fieldName = $this->component->getConfig('imageFieldName'); + if($fieldName != null) + { + // filter out ID at the end: + $fieldName = substr($fieldName, 0, -2); + return $recordHasOneFields[$fieldName]; + } foreach($recordHasOneFields as $field => $type) { if($type == 'Image' || is_subclass_of($type, 'Image')) @@ -306,7 +314,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { // Process the uploaded file if (!$return['error']) { - $fileObject = Object::create($this->getDefaultRecordImageClass()); + $fileObject = Object::create($this->getRecordImageClass()); // Get the uploaded file into a new file object. try {