O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Batch powered update hooks

The first thing we are going to look at is update hooks, revisiting of our previous Sports module created in Chapter 8 , The Database API. We will focus on the &$sandbox parameter we didn't use then. The goal is to run an update on each of our records in the players table and mark them as retired. The point is to illustrate how we can process each of these records one at the time in individual requests to prevent a PHP timeout, in case we have many records.

So to get us going, here is all the code, and we'll see right after what everything means:

/** * Update all the players to mark them as retired. */ function sports_update_8002(&$sandbox) { $database = \Drupal::database(); if (empty($sandbox)) { $results = $database->query("SELECT ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required