Score:1

How to show progress bar twice on one request (with Batch API)

ng flag
863

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?

hotwebmatter avatar
nr flag
Try implementing each Batch API process in its own class.
gb flag
@863, could you share code for the batch callbacks processCallback1, processCallback2?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.