BatchBuilder
class BatchBuilder (View source)
Builds an array for a batch process.
Example code to create a batch:
Properties
| protected array | $operations | The set of operations to be processed. |
|
| protected string|TranslatableMarkup | $title | The title for the batch. |
|
| protected string|TranslatableMarkup | $initMessage | The initializing message for the batch. |
|
| protected string|TranslatableMarkup | $progressMessage | The message to be shown while the batch is in progress. |
|
| protected string|TranslatableMarkup | $errorMessage | The message to be shown if a problem occurs. |
|
| protected string | $finished | The name of a function / method to be called when the batch finishes. |
|
| protected string | $file | The file containing the operation and finished callbacks. |
|
| protected string[] | $libraries | An array of libraries to be included when processing the batch. |
|
| protected array | $urlOptions | An array of options to be used with the redirect URL. |
|
| protected bool | $progressive | Specifies if the batch is progressive. |
|
| protected array | $queue | The details of the queue to use. |
Methods
Sets the default values for the batch builder.
Sets the finished callback.
Sets the displayed message while processing is initialized.
Sets the message to display when the batch is being processed.
Sets the message to display if an error occurs while processing.
Sets the file that contains the callback functions.
Sets the libraries to use when processing the batch.
Sets the options for redirect URLs.
Sets the batch to run progressively.
Sets an override for the default queue.
Adds a batch operation.
Converts a \Drupal\Core\Batch\Batch object into an array.
Details
__construct()
Sets the default values for the batch builder.
$this
setTitle(string|TranslatableMarkup $title)
Sets the title.
$this
setFinishCallback(callable $callback)
Sets the finished callback.
This callback will be executed if the batch process is done.
$this
setInitMessage(string|TranslatableMarkup $message)
Sets the displayed message while processing is initialized.
Defaults to 'Initializing.'.
$this
setProgressMessage(string|TranslatableMarkup $message)
Sets the message to display when the batch is being processed.
Defaults to 'Completed @current of @total.'.
$this
setErrorMessage(string|TranslatableMarkup $message)
Sets the message to display if an error occurs while processing.
Defaults to 'An error has occurred.'.
$this
setFile(string $filename)
Sets the file that contains the callback functions.
The path should be relative to base_path(), and thus should be built using drupal_get_path(). Defaults to {module_name}.module.
The file needs to be set before using ::addOperation(), ::setFinishCallback(), or any other function that uses callbacks from the file. This is so that PHP knows about the included functions.
$this
setLibraries(array $libraries)
Sets the libraries to use when processing the batch.
Adds the libraries for use on the progress page. Any previously added libraries are removed.
$this
setUrlOptions(array $options)
Sets the options for redirect URLs.
$this
setProgressive(bool $is_progressive = TRUE)
Sets the batch to run progressively.
$this
setQueue(string $name, string $class)
Sets an override for the default queue.
The class will typically either be \Drupal\Core\Queue\Batch or \Drupal\Core\Queue\BatchMemory. The class defaults to Batch if progressive is TRUE, or to BatchMemory if progressive is FALSE.
$this
addOperation(callable $callback, array $arguments = [])
Adds a batch operation.
array
toArray()
Converts a \Drupal\Core\Batch\Batch object into an array.