Colymba\BulkTools\HTTPBulkToolsResponse
Custom HTTPResponse for all bulk tools to use for a unified response format and facilitate forn-end handling
Add custom methods and tool to create a common json output format:
{
isDestructive: false,
isError: false,
isWarning: false,
message: "General response error or not message for the cms user",
successClasses: ['list', 'of-new', 'classes', 'to-add', 'bt-done'],
failedClasses: ['list', 'of-new', 'classes', 'to-add', 'bt-done']
records: {
success: [{
id: 1,
class: 'ObjectClass',
row: 'tr .ss-gridfield-item html markup for this record'
}],
failed: [{
id: 2,
class: 'AnotherClass',
message: 'Erro message for that object.'
}]
}
}
- Author: colymba
Synopsis
class HTTPBulkToolsResponse
extends HTTPResponse
{
- // members
- protected array $headers = ;
- protected $removesRows;
- protected string $message = '';
- protected GridField $gridField;
- protected array $successRecords = ;
- protected array $successClasses = ;
- protected array $failedRecords = ;
- protected array $failedClasses = ;
- // methods
- public void __construct()
- public $this addHeader()
- public $this removeHeader()
- public $this setBody()
- public string getBody()
- public $this setMessage()
- public $this addSuccessRecord()
- public $this addSuccessRecords()
- public array getSuccessRecords()
- public $this addFailedRecord()
- public $this addFailedRecords()
- public array getFailedRecords()
- protected string getRecordGridfieldRow()
- public void createBody()
- protected void outputBody()
- public void shutdown()
Hierarchy
Extends
- SilverStripe\Control\HTTPResponse
Members
protected
- $failedClasses
—
array
List of css classes to add to gridfield row with errors - $failedRecords
—
array
List of DataObject IDs that failed to be modified by the bulk action - $gridField
—
SilverStripe\Forms\GridField\GridField
GridField instance. - $headers
—
array
We always return JSON - $message
—
string
Bulk action result message - $removesRows
—
boolean
Does the bulk action removes rows? - $successClasses
—
array
List of css classes to add to gridfield row modified successfully - $successRecords
—
array
List of DataObject that has been modified successfully by the bulk action
Methods
protected
- getRecordGridfieldRow() — Creates a gridfield table row for a given record
- outputBody() — Make sure the body has been created before output Output body of this response to the browser
public
- __construct() — Create a new bulk tools HTTP response
- addFailedRecord() — Add a record to the failed to modified list with its error message
- addFailedRecords() — Add a list of records to the failed to modified list with a common error message
- addHeader() — Overridden here so content-type cannot be changed Add a HTTP header to the response, replacing any header of the same name.
- addSuccessRecord() — Add a record to the successfully modified list
- addSuccessRecords() — Add a list of records to the successfully modified list
- createBody() — Creates the response JSON body
- getBody() — Makes sure body is created before being returned
- getFailedRecords() — Return the list of failed records
- getSuccessRecords() — Return the list of successful records
- removeHeader() — Overriden here so content-type cannot be changed Remove an existing HTTP header by its name, e.g. "Content-Type".
- setBody() — Overridden here so the response body cannot be set manually
- setMessage() — Set the general response message
- shutdown()