GridFieldBulkEditingTools/code/GridFieldBulkImageUpload.php
colymba 51b9518492 Automatic Fields detection + EditForm generation
Component now finds the Image relation and all 'editable fields' itself.
Also gets the edit Forms from the record's getCMSFields()
+ other little fixes
2012-07-18 02:12:10 +03:00

107 lines
2.0 KiB
PHP

<?php
class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLHandler { /*GridField_ActionProvider,*/
/**
* Target record Image foreign key field name
* @var String
*/
protected $recordImageFieldName;
/**
* Target record editablez fields
* @var Array
*/
protected $recordEditableFields;
/**
*
* @param String $imageField
* @param String/Array $editableFields
*/
public function __construct($imageField = null, $editableFields = null)
{
$this->setRecordImageField($imageField);
if ( !is_array($editableFields) && $editableFields != null ) $editableFields = array($editableFields);
$this->setRecordEditableFields($editableFields);
}
/**
*
* @param String $field
*/
function setRecordImageField($field)
{
$this->recordImageFieldName = $field;
}
/**
*
* @param Array $fields
*/
function setRecordEditableFields($fields)
{
$this->recordEditableFields = $fields;
}
/**
*
* @return type
*/
public function getRecordImageField()
{
return $this->recordImageFieldName;
}
/**
*
* @return type
*/
public function getRecordEditableFields()
{
return $this->recordEditableFields;
}
/**
*
* @param GridField $gridField
* @return Array
*/
public function getHTMLFragments($gridField) {
$data = new ArrayData(array(
'NewLink' => $gridField->Link('bulkimageupload'),
'ButtonName' => 'Bulk Upload'
));
return array(
'toolbar-header-right' => $data->renderWith('GridFieldAddNewbutton')
);
}
/**
*
* @param GridField $gridField
* @return Array
*/
public function getURLHandlers($gridField) {
return array(
'bulkimageupload' => 'handleBulkUpload'
);
}
/**
*
* @param type $gridField
* @param type $request
* @return type
*/
public function handleBulkUpload($gridField, $request)
{
$controller = $gridField->getForm()->Controller();
$handler = new GridFieldBulkImageUpload_Request($gridField, $this, $controller);
return $handler->handleRequest($request, DataModel::inst());
}
}