old wagon with signs in it

Overview Batch API in Drupal 8

Tan Nguyen

|

1. Why do we need Batch API
2. How Drupal's Batch API works ?
3. Use cases.

I. Why do we need Batch API

Have you get error related to our-of-memory issue or PHP timeout when perform some expensive tasks like import content from third-party, delete hundred thousand nodes ... in Drupal site ?
Batch API is one of solution for above issue. Drupal’s Batch API support us breaks complex, big task into smaller tasks as real our life, the big thing can be do easier if we break it into smaller parts then handle them.

2. How Drupal's Batch API works ?

Here is a sketch to understand the mechanism of batch in Drupal.

Batch API Drupal 8

3. Use cases

You may see batch when deleting an user account and make its content belong to the Anonymous user in Drupal site (Batch was use because we my have thousand content need make belong Anonymous).

Delete user in Drupal

Or bulk generate URL alias (Batch was used because you may have thousand nodes, medias, users, entities need to update, generate URL alias)

Bulk generate url alias

 

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Comments

  • Allowed HTML tags: <em> <strong> <cite> <blockquote cite> <ul type> <ol start type> <li> <dl> <dt> <dd> <p>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
  • Use [gist:#####] where ##### is your gist number to embed the gist
    You may also include a specific file within a multi-file gist with [gist:####:my_file].

Spread the word