I have a custom form which handles two different process after submission, let's say
- Process 1: removing all article nodes
- Process 2: importing article nodes from csv.
The problem is that each process have to have its own progress bar.So, it should look like:
- Form submitted
- Progress bar for process 1 starts(0%)
- Progress bar for process 1 finishes(100%)
- Progress bar for process 2 starts(0%)
- Progress bar for process 2 finishes(100%)
- Redirect to form
If I add batch_set()
twice in submission handler, both process are executed but progress bar appears only once.
// Create two different batches.
public static function getBatch1() {
$batch_builder = new BatchBuilder();
$batch_builder->setTitle('Process 1')
$batch_builder->addOperation(
[self::class, 'processCallback1'],
);
return $batch_builder->toArray();
}
public static function getBatch2() {
$batch_builder = new BatchBuilder();
$batch_builder->setTitle('Process 2')
$batch_builder->addOperation(
[self::class, 'processCallback2'],
);
return $batch_builder->toArray();
}
// Custom form submission handler.
public function submitForm() {
batch_set(MyBatchClass::getBatch1());
batch_set(MyBatchClass::getBatch2());
}
It actually looks like:
- Form submitted
- Progress bar for process 1 starts(0%)
- Progress bar for process 1 finishes(100%) <- process 2 is also finished in background
- Redirect to form
How can I restart the progress bar when the second process begins?