HTTPBulkToolsResponse
class HTTPBulkToolsResponse extends HTTPResponse (View source)
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.' }] } }
Traits
A class that can be instantiated or replaced via DI
Properties
protected static | array | $status_codes | from HTTPResponse | |
protected static | array | $redirect_codes | from HTTPResponse | |
protected | string | $protocolVersion | from HTTPResponse | |
protected | int | $statusCode | from HTTPResponse | |
protected | string | $statusDescription | from HTTPResponse | |
protected | array | $headers | We always return JSON |
|
protected | string | $body | from HTTPResponse | |
protected | bool | $removesRows | Does the bulk action removes rows? |
|
protected | string | $message | Bulk action result message |
|
protected | GridField | $gridField | GridField instance. |
|
protected | array | $successRecords | List of DataObject that has been modified successfully by the bulk action |
|
protected | array | $successClasses | List of css classes to add to gridfield row modified successfully |
|
protected | array | $failedRecords | List of DataObject IDs that failed to be modified by the bulk action |
|
protected | array | $failedClasses | List of css classes to add to gridfield row with errors |
Methods
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
Create a new bulk tools HTTP response
The HTTP version used to respond to this request (typically 1.0 or 1.1)
The text to be given alongside the status code ("reason phrase").
Overridden here so content-type cannot be changed Add a HTTP header to the response, replacing any header of the same name.
Overriden here so content-type cannot be changed Remove an existing HTTP header by its name, e.g. "Content-Type".
Make sure the body has been created before output Output body of this response to the browser
Returns true if this response is "finished", that is, no more script execution should be done.
Add a record to the failed to modified list with its error message
Add a list of records to the failed to modified list with a common error message
Details
static Injectable
create(mixed ...$args)
An implementation of the factory method, allows you to create an instance of a class
This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.
This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();
static Injectable
singleton(string $class = null)
Creates a class instance by the "singleton" design pattern.
It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).
__construct(bool $removesRows, GridField $gridfield, int $statusCode = null)
Create a new bulk tools HTTP response
$this
setProtocolVersion(string $protocolVersion)
The HTTP version used to respond to this request (typically 1.0 or 1.1)
$this
setStatusCode(int $code, string $description = null)
No description
$this
setStatusDescription(string $description)
The text to be given alongside the status code ("reason phrase").
Caution: Will be overwritten by setStatusCode().
string
getProtocolVersion()
No description
int
getStatusCode()
No description
string
getStatusDescription()
No description
bool
isError()
Returns true if this HTTP response is in error
$this
setBody(string $body)
Overridden here so the response body cannot be set manually
string
getBody()
Makes sure body is created before being returned
$this
addHeader(string $header, string $value)
Overridden here so content-type cannot be changed Add a HTTP header to the response, replacing any header of the same name.
string
getHeader(string $header)
Return the HTTP header of the given name.
array
getHeaders()
No description
$this
removeHeader(string $header)
Overriden here so content-type cannot be changed Remove an existing HTTP header by its name, e.g. "Content-Type".
$this
redirect(string $dest, int $code = 302)
No description
output()
Send this HTTPResponse to the browser
protected
htmlRedirect()
Generate a browser redirect without setting headers
protected
outputHeaders()
Output HTTP headers to the browser
protected
outputBody()
Make sure the body has been created before output Output body of this response to the browser
bool
isFinished()
Returns true if this response is "finished", that is, no more script execution should be done.
Specifically, returns true if a redirect has already been requested
bool
isRedirect()
Determine if this response is a redirect
string
__toString()
The HTTP response represented as a raw string
$this
setMessage(string $message)
Set the general response message
$this
addSuccessRecord(DataObject $record)
Add a record to the successfully modified list
$this
addSuccessRecords(SS_List $records)
Add a list of records to the successfully modified list
array
getSuccessRecords()
Return the list of successful records
$this
addFailedRecord(DataObject $record, string $message)
Add a record to the failed to modified list with its error message
$this
addFailedRecords(SS_List $records, string $message)
Add a list of records to the failed to modified list with a common error message
array
getFailedRecords()
Return the list of failed records
protected string
getRecordGridfieldRow(DataObject $record)
Creates a gridfield table row for a given record
createBody()
Creates the response JSON body
shutdown()
deprecated
deprecated
No description