Merge pull request #14 from s-m/image-subclass

NEW: Subclasses of Image are now instantiated and used
This commit is contained in:
Thierry François 2013-02-02 08:18:16 -08:00
commit da1ee363b4

View File

@ -110,7 +110,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
$imageField = null; $imageField = null;
foreach( $recordHasOneFields as $field => $type ) foreach( $recordHasOneFields as $field => $type )
{ {
if ( $type == 'Image' ) { if($type == 'Image' || is_subclass_of($type, 'Image')) {
$imageField = $field . 'ID'; $imageField = $field . 'ID';
break; break;
} }
@ -118,7 +118,27 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
return $imageField; 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 * @param type $recordID
@ -283,7 +303,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
// Process the uploaded file // Process the uploaded file
if (!$return['error']) { if (!$return['error']) {
$fileObject = Object::create('Image'); $fileObject = Object::create($this->getDefaultRecordImageClass());
// Get the uploaded file into a new file object. // Get the uploaded file into a new file object.
try { try {