API for easily creating batches.

Implementation info

Create a class that extends the EnumeratedBatchBase or HighwaterBatchBase. In here you'll need to build-out the ::processItem method and a couple other methods involved in obtaining items, etc.

Invoke your batch class via form submit:

// Injected batch.factory service.
$batch = $this->batchFactory->getBatchFromClass(\Drupal\my_module\Batch\AwesomeBatch::class)
  ->setIds($this->gpraExport->getExportNids($group))
  ->getBatch();

batch_set($batch);

Or run your class via Drush:

// Injected batch.factory service.
$batchObj = $this->getBatchFactory()
  ->getBatchFromClass(\Drupal\my_module\Batch\AwesomeBatch::class);
$batch = $batchObj->getBatch();
batch_set($batch);
$batch =& batch_get();
$batch['progressive'] = FALSE;

// Process the batch.
drush_backend_batch_process();

Project information

Releases