You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please add a command to generate batch service.
Currently there is no command to generate batch class.
Hence we need to code same boilerplate code again and again.
Please Create a generator class to generate batch service.
The text was updated successfully, but these errors were encountered:
Introduce a new generator command: generate:batch-service, which will create a batch service class with the required structure to use Drupal's Batch API.
namespace {{ namespace }};
use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class {{ class }} {
use StringTranslationTrait;
public function buildBatch(array $items) {
$batch_builder = new BatchBuilder();
$batch_builder
->setTitle($this->t('Processing items...'))
->setFinishCallback([$this, '{{ finished_callback|default("finished") }}']);
foreach ($items as $item) {
$batch_builder->addOperation([$this, '{{ operation_callback|default("processItem") }}'], [$item]);
}
return $batch_builder->toArray();
}
public function {{ operation_callback|default("processItem") }}($item, array &$context) {
// TODO: Implement batch processing logic.
}
public function {{ finished_callback|default("finished") }}(bool $success, array $results, array $operations) {
if ($success) {
// TODO: Implement batch processing logic.
}
else {
// TODO: Implement batch processing logic.
}
}
}
Lets me know if you any suggestion, Other wise I would start working on feature
Please add a command to generate batch service.
Currently there is no command to generate batch class.
Hence we need to code same boilerplate code again and again.
Please Create a generator class to generate batch service.
The text was updated successfully, but these errors were encountered: