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
|
## Usage 2
|
||||||
You can specify which `Image` or `File` field to use and a specific `DataObject` class name to use.
|
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')
|
$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
|
## Configuration
|
||||||
### Component configuration
|
### Component configuration
|
||||||
|
@ -10,13 +10,13 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
* Component configuration.
|
* Component configuration.
|
||||||
*
|
*
|
||||||
* 'fileRelationName' => field name of the $has_one File/Image relation
|
* '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
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $config = array(
|
protected $config = array(
|
||||||
'fileRelationName' => null,
|
'fileRelationName' => null,
|
||||||
'objectClassName' => null
|
'recordClassName' => null
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,14 +68,14 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
*
|
*
|
||||||
* @param string $fileRelationName
|
* @param string $fileRelationName
|
||||||
*/
|
*/
|
||||||
public function __construct($fileRelationName = null, $objectClassName = null)
|
public function __construct($fileRelationName = null, $recordClassName = null)
|
||||||
{
|
{
|
||||||
if ($fileRelationName != null) {
|
if ($fileRelationName != null) {
|
||||||
$this->setConfig('fileRelationName', $fileRelationName);
|
$this->setConfig('fileRelationName', $fileRelationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($objectClassName != null) {
|
if ($recordClassName != null) {
|
||||||
$this->setConfig('objectClassName', $objectClassName);
|
$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
|
* Get the first has_one Image/File relation from the GridField managed DataObject
|
||||||
* i.e. 'MyImage' => 'Image' will return 'MyImage'.
|
* i.e. 'MyImage' => 'Image' will return 'MyImage'.
|
||||||
@ -221,7 +232,7 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
*/
|
*/
|
||||||
public function getDefaultFileRelationName($gridField)
|
public function getDefaultFileRelationName($gridField)
|
||||||
{
|
{
|
||||||
$recordClass = $gridField->list->dataClass;
|
$recordClass = $this->getRecordClassName($gridField);
|
||||||
$hasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED);
|
$hasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED);
|
||||||
|
|
||||||
$imageField = null;
|
$imageField = null;
|
||||||
@ -257,7 +268,7 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
*/
|
*/
|
||||||
public function getFileRelationClassName($gridField)
|
public function getFileRelationClassName($gridField)
|
||||||
{
|
{
|
||||||
$recordClass = $gridField->list->dataClass;
|
$recordClass = $this->getRecordClassName($gridField);
|
||||||
$hasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED);
|
$hasOneFields = Config::inst()->get($recordClass, 'has_one', Config::INHERITED);
|
||||||
|
|
||||||
$fieldName = $this->getFileRelationName($gridField);
|
$fieldName = $this->getFileRelationName($gridField);
|
||||||
|
@ -83,11 +83,7 @@ class GridFieldBulkUpload_Request extends RequestHandler
|
|||||||
public function upload(SS_HTTPRequest $request)
|
public function upload(SS_HTTPRequest $request)
|
||||||
{
|
{
|
||||||
//create record
|
//create record
|
||||||
if ($this->component->getConfig('objectClassName')) {
|
$recordClass = $this->component->getRecordClassName($this->gridField);
|
||||||
$recordClass = $this->component->getConfig('objectClassName');
|
|
||||||
} else {
|
|
||||||
$recordClass = $this->gridField->list->dataClass;
|
|
||||||
}
|
|
||||||
$record = Object::create($recordClass);
|
$record = Object::create($recordClass);
|
||||||
$record->write();
|
$record->write();
|
||||||
|
|
||||||
@ -230,7 +226,7 @@ class GridFieldBulkUpload_Request extends RequestHandler
|
|||||||
$attachResponses = json_decode($attachResponses->getBody(), true);
|
$attachResponses = json_decode($attachResponses->getBody(), true);
|
||||||
|
|
||||||
$fileRelationName = $uploadField->getName();
|
$fileRelationName = $uploadField->getName();
|
||||||
$recordClass = $this->gridField->list->dataClass;
|
$recordClass = $this->component->getRecordClassName($this->gridField);
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
foreach ($attachResponses as $attachResponse) {
|
foreach ($attachResponses as $attachResponse) {
|
||||||
|
Loading…
Reference in New Issue
Block a user