Skip to content

Commit

Permalink
Enhancement: SilverStripe 4 compatibility (#137)
Browse files Browse the repository at this point in the history
* Basic SS4 compat: Implemented namespacing, updated some Image manipulations, readmes, composer configuration

* Add bootstrap form styles to the bulk manager

* API Rename classes to be less confusing with the namespaces
  • Loading branch information
robbieaverill authored and colymba committed Jan 25, 2017
1 parent 0e6f2e6 commit 7221897
Show file tree
Hide file tree
Showing 25 changed files with 520 additions and 325 deletions.
10 changes: 10 additions & 0 deletions .upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mappings:
GridFieldBulkActionDeleteHandler: Colymba\BulkManager\BulkAction\DeleteHandler
GridFieldBulkActionEditHandler: Colymba\BulkManager\BulkAction\EditHandler
GridFieldBulkActionHandler: Colymba\BulkManager\BulkAction\Handler
GridFieldBulkActionUnlinkHandler: Colymba\BulkManager\BulkAction\UnlinkHandler
GridFieldBulkManager: Colymba\BulkManager\BulkManager
BulkUploadField: Colymba\BulkUpload\BulkUploadField
GridFieldBulkImageUpload: Colymba\BulkUpload\GridFieldBulkImageUpload
GridFieldBulkUpload: Colymba\BulkUpload\BulkUploader
GridFieldBulkUpload_Request: Colymba\BulkUpload\BulkUploadRequest
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GridField Bulk Editing Tools
[![Latest Unstable Version](https://poser.pugx.org/colymba/gridfield-bulk-editing-tools/v/unstable.svg)](https://github.com/colymba/GridFieldBulkEditingTools/tree/master)
[![License](https://poser.pugx.org/colymba/gridfield-bulk-editing-tools/license.svg)](#license-bsd-simplified)

Set of SilverStripe 3 GridField components to facilitate bulk file upload & record editing.
Set of SilverStripe 4 GridField components to facilitate bulk file upload & record editing.

![preview](screenshots/preview.png)

Expand All @@ -16,37 +16,47 @@ Set of SilverStripe 3 GridField components to facilitate bulk file upload & reco
[More screenshots here.](screenshots)

## Requirements
* SilverStripe 3.1 (version master / 2.+ / 1.+)
* SilverStripe 4.0 (version master / 3.+)
* SilverStripe 3.1 (version 2.+ / 1.+)
* Silverstripe 3.0 (version [0.5](https://github.com/colymba/GridFieldBulkEditingTools/tree/0.5))

## Installation
### Composer
* `composer require "colymba/gridfield-bulk-editing-tools:*"`
* `composer require colymba/gridfield-bulk-editing-tools`

### Manual
* Download and copy module in SilverStripe root directory

## 3.0.0 deprecations
The 3.x versions of this module require SilverStripe 4.x+, and PHP 5.5 or above:

* Namespaces are implemented, and some class names have changed (see `.upgrade.yml` for mapping)

## 2.0.0 deprecations
Major depractions in latest 2.0.0 release:
Major deprections in latest 2.0.0 release:
* The `GridFieldBulkImageUpload` has been renamed to `GridFieldBulkUpload`.
* `onBulkImageUpload` callback has been renamed to `onBulkUpload`

## Bulk Upload
Upload multiple images or files at once into DataObjects. Perfect for galleries and the like.

$config->addComponent(new GridFieldBulkUpload());
```php
$config->addComponent(new \Colymba\BulkUpload\BulkUploader());
```

See [BULK_UPLOAD.md](bulkUpload/BULK_UPLOAD.md) for detailed configuration.

## Bulk Manager
Perform actions on multiple records straight from the GridField

$config->addComponent(new GridFieldBulkManager());
```php
$config->addComponent(new \Colymba\BulkManager\BulkManager());
```

See [BULK_MANAGER.md](bulkManager/BULK_MANAGER.md) for detailed configuration.

## Interdependencies
The `GridFieldBulkUpload` component makes use of `GridFieldBulkManager` to allow quick editing of the newly uploaded files. Although not nescessary for the component to work, adding `GridFieldBulkManager` too to your `GridFieldConfig` will give you this advantage.
The `BulkUploader` component makes use of `BulkManager` to allow quick editing of the newly uploaded files. Although not nescessary for the component to work, adding `Colymba\BulkManager\BulkManager` too to your `GridFieldConfig` will give you this advantage.

#### @TODO
* Add individual actions for each upload (update + cancel)
Expand All @@ -69,5 +79,5 @@ Redistribution and use in source and binary forms, with or without modification,
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Thierry Francois, colymba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 2 additions & 2 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
if (!defined('BULKEDITTOOLS_PATH')) {
$folder = rtrim(basename(dirname(__FILE__)));
define('BULKEDITTOOLS_PATH', $folder);
define('BULKEDITTOOLS_UPLOAD_PATH', $folder.'/bulkUpload');
define('BULKEDITTOOLS_MANAGER_PATH', $folder.'/bulkManager');
define('BULKEDITTOOLS_UPLOAD_PATH', $folder . '/bulkUpload');
define('BULKEDITTOOLS_MANAGER_PATH', $folder . '/bulkManager');
}
22 changes: 0 additions & 22 deletions build.xml

This file was deleted.

26 changes: 17 additions & 9 deletions bulkManager/BULK_MANAGER.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ Perform actions on multiple records straight from the GridField. Comes with *unl

## Usage
Simply add component to your `GridFieldConfig`

$config->addComponent(new GridFieldBulkManager());


```php
$config->addComponent(new \Colymba\BulkManager\BulkManager());
```

## Configuration
The component's options can be configurated individually or in bulk through the 'config' functions like this:

$config->getComponentByType('GridFieldBulkManager')->setConfig($reference, $value);
```php
$config->getComponentByType('Colymba\\BulkManager\\BulkManager')->setConfig($reference, $value);
```

### $config overview
The available configuration options are:
* 'editableFields' : array of string referencing specific CMS fields available for editing
Expand All @@ -21,19 +25,23 @@ You can remove or add individual action or replace them all via `addBulkAction()
### Adding a custom action
To add a custom bulk action to the list use:

$config->getComponentByType('GridFieldBulkManager')->addBulkAction('actionName', 'Dropdown label', 'ActionHandlerClassName', $frontEndConfig)
```php
$config
->getComponentByType('Colymba\\BulkManager\\BulkManager')
->addBulkAction('actionName', 'Dropdown label', 'ActionHandlerClassName', $frontEndConfig)
```

You can omit the handler's class name and the front-end config array, those will default to:
* `'GridFieldBulkAction'.ucfirst($name).'Handler'`
* `$config = array( 'isAjax' => true, 'icon' => 'accept', 'isDestructive' => false )`

#### Custom action handler
When creating your own bulk action `RequestHandler`, you should extend `GridFieldBulkActionHandler` which will expose 2 usefull functions `getRecordIDList()` and `getRecords()` returning either an array with the selected records IDs or a `DataList` of the selected records.
When creating your own bulk action `RequestHandler`, you should extend `Colymba\BulkManager\BulkAction\Handler` which will expose 2 useful functions `getRecordIDList()` and `getRecords()` returning either an array with the selected records IDs or a `DataList` of the selected records.

Make sure to define your `$allowed_actions` and `$url_handlers` on your custom bulk action handler. See `GridFieldBulkActionEditHandler`, `GridFieldBulkActionDeleteHandler` and `GridFieldBulkActionUnlinkHandler` for examples.
Make sure to define your `$allowed_actions` and `$url_handlers` on your custom bulk action handler. See `Handler`, `DeleteHandler` and `UnlinkHandler` for examples.

#### Front-end config
The last `addBulkAction()` parameter lets you pass an array with configuration options for the UI/UX:
* `isAjax`: if true the action will be called via XHR request otherwise the browser will be redirected to the action's URL
* `icon`: lets you define which icon to use on the button when the action is selected (SilverStripe button icon name only)
* `isDestructive`: if true, a confirmation dialog will be shown before the action is processed
* `isDestructive`: if true, a confirmation dialog will be shown before the action is processed
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<?php

namespace Colymba\BulkManager\BulkAction;

use Colymba\BulkManager\BulkAction\Handler;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;

/**
* Bulk action handler for deleting records.
*
*
* @author colymba
*/
class GridFieldBulkActionDeleteHandler extends GridFieldBulkActionHandler
class DeleteHandler extends Handler
{
/**
* RequestHandler allowed actions.
Expand All @@ -24,12 +32,12 @@ class GridFieldBulkActionDeleteHandler extends GridFieldBulkActionHandler

/**
* Delete the selected records passed from the delete bulk action.
*
* @param SS_HTTPRequest $request
*
* @return SS_HTTPResponse List of deleted records ID
* @param HTTPRequest $request
*
* @return HTTPResponse List of deleted records ID
*/
public function delete(SS_HTTPRequest $request)
public function delete(HTTPRequest $request)
{
$ids = array();

Expand All @@ -38,7 +46,7 @@ public function delete(SS_HTTPRequest $request)
$record->delete();
}

$response = new SS_HTTPResponse(Convert::raw2json(array(
$response = new HTTPResponse(Convert::raw2json(array(
'done' => true,
'records' => $ids,
)));
Expand Down
Loading

0 comments on commit 7221897

Please sign in to comment.