March 2019
Intermediate to advanced
580 pages
15h 3m
English
Inside the JsonImporter::import() method, once we get our hands on the $products array, let's replace the loop with the following:
$batch_builder = (new BatchBuilder())
->setTitle($this->t('Importing products'))
->setFinishCallback([$this, 'importProductsFinished']);
$batch_builder->addOperation([$this, 'clearMissing'], [$products]);
$batch_builder->addOperation([$this, 'importProducts'], [$products]);
batch_set($batch_builder->toArray());
And the new use statement at the top:
use Drupal\Core\Batch\BatchBuilder;
Creating a batch involves a number of steps, the first one being the creation of a batch definition, which is nothing more than an array with some data. Before version 8.6 of Drupal, the batch definition was created ...
Read now
Unlock full access