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

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(bool $removesRows, GridField $gridfield, int $statusCode = null)

Create a new bulk tools HTTP response

public
$this
setProtocolVersion(string $protocolVersion)

The HTTP version used to respond to this request (typically 1.0 or 1.1)

public
$this
setStatusCode(int $code, string $description = null)

No description

public
$this
setStatusDescription(string $description)

The text to be given alongside the status code ("reason phrase").

public
string
getProtocolVersion()

No description

public
int
getStatusCode()

No description

public
string
getStatusDescription()

No description

public
bool
isError()

Returns true if this HTTP response is in error

public
$this
setBody(string $body)

Overridden here so the response body cannot be set manually

public
string
getBody()

Makes sure body is created before being returned

public
$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.

public
string
getHeader(string $header)

Return the HTTP header of the given name.

public
array
getHeaders()

No description

public
$this
removeHeader(string $header)

Overriden here so content-type cannot be changed Remove an existing HTTP header by its name, e.g. "Content-Type".

public
$this
redirect(string $dest, int $code = 302)

No description

public
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

public
bool
isFinished()

Returns true if this response is "finished", that is, no more script execution should be done.

public
bool
isRedirect()

Determine if this response is a redirect

public
string
__toString()

The HTTP response represented as a raw string

public
$this
setMessage(string $message)

Set the general response message

public
$this
addSuccessRecord(DataObject $record)

Add a record to the successfully modified list

public
$this
addSuccessRecords(SS_List $records)

Add a list of records to the successfully modified list

public
array
getSuccessRecords()

Return the list of successful records

public
$this
addFailedRecord(DataObject $record, string $message)

Add a record to the failed to modified list with its error message

public
$this
addFailedRecords(SS_List $records, string $message)

Add a list of records to the failed to modified list with a common error message

public
array
getFailedRecords()

Return the list of failed records

protected
string
getRecordGridfieldRow(DataObject $record)

Creates a gridfield table row for a given record

public
createBody()

Creates the response JSON body

public
shutdown() deprecated

No description

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();

Parameters

mixed ...$args

Return Value

Injectable

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).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(bool $removesRows, GridField $gridfield, int $statusCode = null)

Create a new bulk tools HTTP response

Parameters

bool $removesRows

Does the action removes rows?

GridField $gridfield

gridfield instance that holds the records list

int $statusCode

The numeric status code - 200, 404, etc

$this setProtocolVersion(string $protocolVersion)

The HTTP version used to respond to this request (typically 1.0 or 1.1)

Parameters

string $protocolVersion

Return Value

$this

$this setStatusCode(int $code, string $description = null)

No description

Parameters

int $code
string $description

Optional. See setStatusDescription(). No newlines are allowed in the description. If omitted, will default to the standard HTTP description for the given $code value (see $status_codes).

Return Value

$this

$this setStatusDescription(string $description)

The text to be given alongside the status code ("reason phrase").

Caution: Will be overwritten by setStatusCode().

Parameters

string $description

Return Value

$this

string getProtocolVersion()

No description

Return Value

string

int getStatusCode()

No description

Return Value

int

string getStatusDescription()

No description

Return Value

string

Description for a HTTP status code

bool isError()

Returns true if this HTTP response is in error

Return Value

bool

$this setBody(string $body)

Overridden here so the response body cannot be set manually

Parameters

string $body

Return Value

$this

string getBody()

Makes sure body is created before being returned

Return Value

string

$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.

Parameters

string $header

Example: "content-type"

string $value

Example: "text/xml"

Return Value

$this

string getHeader(string $header)

Return the HTTP header of the given name.

Parameters

string $header

Return Value

string

array getHeaders()

No description

Return Value

array

$this removeHeader(string $header)

Overriden here so content-type cannot be changed Remove an existing HTTP header by its name, e.g. "Content-Type".

Parameters

string $header

Return Value

$this

$this redirect(string $dest, int $code = 302)

No description

Parameters

string $dest
int $code

Return Value

$this

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

Return Value

bool

bool isRedirect()

Determine if this response is a redirect

Return Value

bool

string __toString()

The HTTP response represented as a raw string

Return Value

string

$this setMessage(string $message)

Set the general response message

Parameters

string $message

Return Value

$this

$this addSuccessRecord(DataObject $record)

Add a record to the successfully modified list

Parameters

DataObject $record

the newly modified dataObject

Return Value

$this

$this addSuccessRecords(SS_List $records)

Add a list of records to the successfully modified list

Parameters

SS_List $records

newly modified dataObjects list

Return Value

$this

array getSuccessRecords()

Return the list of successful records

Return Value

array

$this addFailedRecord(DataObject $record, string $message)

Add a record to the failed to modified list with its error message

Parameters

DataObject $record

the failed dataObject

string $message

error message

Return Value

$this

$this addFailedRecords(SS_List $records, string $message)

Add a list of records to the failed to modified list with a common error message

Parameters

SS_List $records

the failed dataObject list

string $message

error message

Return Value

$this

array getFailedRecords()

Return the list of failed records

Return Value

array

protected string getRecordGridfieldRow(DataObject $record)

Creates a gridfield table row for a given record

Parameters

DataObject $record

the record to create the row for

Return Value

string

the html TR tag

createBody()

Creates the response JSON body

shutdown() deprecated

deprecated 3.1.0 This function was used to catch PHP Errors and inject additional information in the response

No description