mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
FIX lost commit
This commit is contained in:
parent
af7524efd1
commit
f924e7d503
@ -9,9 +9,9 @@ Simplest usage, add the component to your `GridFieldConfig` as below. The compon
|
||||
## Usage 2
|
||||
You can specify which `Image` or `File` field to use and a specific `DataObject` class name to use.
|
||||
$fileRelationName (string, optional): The name of the `Image` or `File` has_one field to use (If your relation is set has 'MyImage' => 'Image', the parameter should be 'MyImage')
|
||||
$objectClassName (string, optional): The class name of the `DataObject` to create (Usefull if for example your `GridField` holds `DataObject`s of different classes, like when used with the `GridFieldAddNewMultiClass` component.)
|
||||
$recordClassName (string, optional): The class name of the `DataObject` to create (Usefull if for example your `GridField` holds `DataObject`s of different classes, like when used with the `GridFieldAddNewMultiClass` component.)
|
||||
|
||||
$config->addComponent(new GridFieldBulkUpload($fileRelationName, $objectClassName));
|
||||
$config->addComponent(new GridFieldBulkUpload($fileRelationName, $recordClassName));
|
||||
|
||||
## Configuration
|
||||
### Component configuration
|
||||
|
@ -10,13 +10,13 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
||||
* Component configuration.
|
||||
*
|
||||
* 'fileRelationName' => field name of the $has_one File/Image relation
|
||||
* 'objectClassName' => overrides the automatic DataObject class detection from gridfield->dataClass with a custom class name
|
||||
* 'recordClassName' => overrides the automatic DataObject class detection from gridfield->dataClass with a custom class name
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array(
|
||||
'fileRelationName' => null,
|
||||
'objectClassName' => null
|
||||
'recordClassName' => null
|
||||
);
|
||||
|
||||
/**
|
||||
@ -68,14 +68,14 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
||||
*
|
||||
* @param string $fileRelationName
|
||||
*/
|
||||
public function __construct($fileRelationName = null, $objectClassName = null)
|
||||
public function __construct($fileRelationName = null, $recordClassName = null)
|
||||
{
|
||||
if ($fileRelationName != null) {
|
||||
$this->setConfig('fileRelationName', $fileRelationName);
|
||||
}
|
||||
|
||||
if ($objectClassName != null) {
|
||||
$this->setConfig('objectClassName', $objectClassName);
|
||||
if ($recordClassName != null) {
|
||||
$this->setConfig('recordClassName', $recordClassName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,6 +213,17 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class name of container `DataObject` record.
|
||||
* Either as set in the component config or fron the `Gridfield` `dataClass.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRecordClassName($gridField)
|
||||
{
|
||||
return $this->getConfig('recordClassName') ? $this->getConfig('recordClassName') : $gridField->list->dataClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first has_one Image/File relation from the GridField managed DataObject
|
||||
* i.e. 'MyImage' => 'Image' will return 'MyImage'.
|
||||
@ -221,7 +232,7 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
||||
*/
|
||||
public function getDefaultFileRelationName($gridField)
|
||||
{
|
||||
$recordClass = $gridField->list->dataClass;
|
||||
$recordClass = $this->getRecordClassName($gridField);
|
||||
$hasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED);
|
||||
|
||||
$imageField = null;
|
||||
@ -257,7 +268,7 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
||||
*/
|
||||
public function getFileRelationClassName($gridField)
|
||||
{
|
||||
$recordClass = $gridField->list->dataClass;
|
||||
$recordClass = $this->getRecordClassName($gridField);
|
||||
$hasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED);
|
||||
|
||||
$fieldName = $this->getFileRelationName($gridField);
|
||||
|
@ -83,11 +83,7 @@ class GridFieldBulkUpload_Request extends RequestHandler
|
||||
public function upload(SS_HTTPRequest $request)
|
||||
{
|
||||
//create record
|
||||
if ($this->component->getConfig('objectClassName')) {
|
||||
$recordClass = $this->component->getConfig('objectClassName');
|
||||
} else {
|
||||
$recordClass = $this->gridField->list->dataClass;
|
||||
}
|
||||
$recordClass = $this->component->getRecordClassName($this->gridField);
|
||||
$record = Object::create($recordClass);
|
||||
$record->write();
|
||||
|
||||
@ -230,7 +226,7 @@ class GridFieldBulkUpload_Request extends RequestHandler
|
||||
$attachResponses = json_decode($attachResponses->getBody(), true);
|
||||
|
||||
$fileRelationName = $uploadField->getName();
|
||||
$recordClass = $this->gridField->list->dataClass;
|
||||
$recordClass = $this->component->getRecordClassName($this->gridField);
|
||||
$return = array();
|
||||
|
||||
foreach ($attachResponses as $attachResponse) {
|
||||
|
Loading…
Reference in New Issue
Block a user