mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
Updated comments and Readme
Added comments and credits and updated README
This commit is contained in:
parent
56a4bb4681
commit
1ac1c88cd6
11
README.md
11
README.md
@ -2,7 +2,7 @@ GridFieldBulkImageUpload
|
||||
========================
|
||||
|
||||
SilverStripe 3 GridField component for uploading images in bulk into the managed DataObject relation, with option to edit fields on the fly.
|
||||
This component is built around the CMSFileAddController editForm, it overrides and adds some behaviors, templates and styles.
|
||||
This component takes bit and pieces around from CMSFileAddController, GridFieldDetailForm_ItemRequest, UploadField, and it overrides and adds some behaviors, templates and styles.
|
||||
|
||||
## Requirments
|
||||
* SilverStripe 3.0
|
||||
@ -20,8 +20,8 @@ Simplest usage, add the component to your GridField as below. The component will
|
||||
|
||||
## Usage 2
|
||||
Same as 1 but you can specify which Image field to use and which fields are editable
|
||||
$imageField: The name of the image field to use (should have 'ID' at the end: If your relation is set has 'MyImage' => 'Image', the parameter should be 'MyImageID')
|
||||
$editableFields: An array of db fields name that will be editable like array('myTextField', 'myVarcharField', 'myEnumField')
|
||||
$imageField: string: The name of the image field to use (should have 'ID' at the end: If your relation is set has 'MyImage' => 'Image', the parameter should be 'MyImageID')
|
||||
$editableFields: array: list of db fields name as string that will be editable like: array('myTextField', 'myVarcharField', 'myEnumField')
|
||||
|
||||
:::php
|
||||
$config->addComponent(new GridFieldBulkImageUpload( $imageField, $editableFields ));
|
||||
@ -30,5 +30,8 @@ $editableFields: An array of db fields name that will be editable like array('my
|
||||
* The HTML form fields for each editable fields are taken from the DataObject's getCMSFields() method
|
||||
* Only (HTML)Text/Varchar and Enum fields are picked up by the automatic config
|
||||
|
||||
## TODO
|
||||
## @TODO
|
||||
* Add option to specify upload folder
|
||||
* Styles: fade back progress to blue once updated
|
||||
* Handle and display errors better for: creation, update, cancel
|
||||
* Make it work not only for images -> might need to rename this component then?
|
@ -1,23 +1,27 @@
|
||||
<?php
|
||||
|
||||
class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLHandler { /*GridField_ActionProvider,*/
|
||||
/**
|
||||
* GridField component for uploading images in bulk
|
||||
*/
|
||||
class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLHandler {
|
||||
|
||||
/**
|
||||
* Target record Image foreign key field name
|
||||
* @var String
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $recordImageFieldName;
|
||||
|
||||
/**
|
||||
* Target record editablez fields
|
||||
* @var Array
|
||||
* Target record editable fields
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $recordEditableFields;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param String $imageField
|
||||
* @param String/Array $editableFields
|
||||
* @param string $imageField
|
||||
* @param string/array $editableFields
|
||||
*/
|
||||
public function __construct($imageField = null, $editableFields = null)
|
||||
{
|
||||
@ -29,7 +33,7 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
|
||||
|
||||
/**
|
||||
*
|
||||
* @param String $field
|
||||
* @param string $field
|
||||
*/
|
||||
function setRecordImageField($field)
|
||||
{
|
||||
@ -38,7 +42,7 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Array $fields
|
||||
* @param array $fields
|
||||
*/
|
||||
function setRecordEditableFields($fields)
|
||||
{
|
||||
@ -47,7 +51,7 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
|
||||
|
||||
/**
|
||||
*
|
||||
* @return type
|
||||
* @return string
|
||||
*/
|
||||
public function getRecordImageField()
|
||||
{
|
||||
@ -56,7 +60,7 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
|
||||
|
||||
/**
|
||||
*
|
||||
* @return type
|
||||
* @return string
|
||||
*/
|
||||
public function getRecordEditableFields()
|
||||
{
|
||||
@ -66,7 +70,7 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
|
||||
/**
|
||||
*
|
||||
* @param GridField $gridField
|
||||
* @return Array
|
||||
* @return array
|
||||
*/
|
||||
public function getHTMLFragments($gridField) {
|
||||
|
||||
@ -83,7 +87,7 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
|
||||
/**
|
||||
*
|
||||
* @param GridField $gridField
|
||||
* @return Array
|
||||
* @return array
|
||||
*/
|
||||
public function getURLHandlers($gridField) {
|
||||
return array(
|
||||
@ -92,10 +96,11 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass control over to the RequestHandler
|
||||
*
|
||||
* @param type $gridField
|
||||
* @param type $request
|
||||
* @return type
|
||||
* @param GridField $gridField
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function handleBulkUpload($gridField, $request)
|
||||
{
|
||||
|
@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handles request from the GridFieldBulkImageUpload component
|
||||
*
|
||||
* Handles:
|
||||
* * Form creation
|
||||
* * file upload
|
||||
* * editing and cancelling records
|
||||
*/
|
||||
class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
|
||||
/**
|
||||
@ -21,6 +28,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
protected $controller;
|
||||
|
||||
/**
|
||||
* Cache the records FieldList from getCMSfields()
|
||||
*
|
||||
* @var FieldList
|
||||
*/
|
||||
@ -50,8 +58,10 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
/**
|
||||
* Returns the URL for this RequestHandler
|
||||
*
|
||||
* @param String $action
|
||||
* @return String
|
||||
* @author SilverStripe
|
||||
* @see GridFieldDetailForm_ItemRequest
|
||||
* @param string $action
|
||||
* @return string
|
||||
*/
|
||||
public function Link($action = null) {
|
||||
return Controller::join_links($this->gridField->Link(), 'bulkimageupload', $action);
|
||||
@ -108,7 +118,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of the GridField managed DataObject (HTML)Text, (HTML)Varchar and Enum fields
|
||||
* Return a list of the GridField managed DataObject's editable fields: (HTML)Text, (HTML)Varchar and Enum fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -130,6 +140,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
|
||||
/**
|
||||
* Return the CMS edit field for a given name. As set in the GridField managed DataObject getCMSFields method
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return FormField
|
||||
*/
|
||||
@ -145,7 +156,8 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
|
||||
/**
|
||||
* Default and main action that returns the upload form etc...
|
||||
* @return String Form HTML ???
|
||||
*
|
||||
* @return string Form's HTML
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
@ -229,8 +241,14 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
* Create new DataObject and add image relation
|
||||
* returns Image data and editable Fields forms
|
||||
*
|
||||
* Overides UploadField's upload method by Zauberfisch
|
||||
* Kept original file upload/processing but removed unessesary processing
|
||||
* and adds DataObject creation and editableFields processing
|
||||
*
|
||||
* @author Zauberfisch original upload() method
|
||||
* @see UploadField->upload()
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return \SS_HTTPResponse
|
||||
* @return string json
|
||||
*/
|
||||
public function upload(SS_HTTPRequest $request)
|
||||
{
|
||||
@ -315,7 +333,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
* Update a record with the newly edited fields
|
||||
*
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return String
|
||||
* @return string
|
||||
*/
|
||||
public function update(SS_HTTPRequest $request)
|
||||
{
|
||||
@ -339,7 +357,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
* according to the ID sent from the form
|
||||
*
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return String JSON
|
||||
* @return string json
|
||||
*/
|
||||
public function cancel(SS_HTTPRequest $request)
|
||||
{
|
||||
@ -366,7 +384,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple function taht replace the 'record_XX_' off of the ID field name
|
||||
* Simple function that replace the 'record_XX_' off of the ID field name
|
||||
* prefix needed since it was taken for a pageID if sent as is as well as fixing other things
|
||||
*
|
||||
* @param array $data
|
||||
@ -401,10 +419,15 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Edited version of the GridFieldEditForm function
|
||||
* adds the 'Bulk Upload' at the end of the crums
|
||||
*
|
||||
* CMS-specific functionality: Passes through navigation breadcrumbs
|
||||
* to the template, and includes the currently edited record (if any).
|
||||
* see {@link LeftAndMain->Breadcrumbs()} for details.
|
||||
*
|
||||
* @author SilverStripe original Breadcrumbs() method
|
||||
* @see GridFieldDetailForm_ItemRequest
|
||||
* @param boolean $unlinked
|
||||
* @return ArrayData
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user