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 operations

Now that we have our batch definition in place, we are missing those three callback methods we are referencing in it. So, let's see the first one:

/** * Batch operation to remove the products which are no longer in the list of * products coming from the JSON file. * * @param $products * @param $context */ public function clearMissing($products, &$context) { if (!isset($context['results']['cleared'])) { $context['results']['cleared'] = []; } if (!$products) { return; } $ids = []; foreach ($products as $product) { $ids[] = $product->id; } $ids = $this->entityTypeManager->getStorage('product')->getQuery() ->condition('remote_id', $ids, 'NOT IN') ->execute(); if (!$ids) { $context['results']['cleared'] = []; return; } $entities ...

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