You are here

private function MediaDevelGenerate::generateBatchMedia in Media entity 8

Method for creating media when number of elements is greater than 50.

Parameters

array $values: The input values from the settings form.

1 call to MediaDevelGenerate::generateBatchMedia()
MediaDevelGenerate::generateElements in src/Plugin/DevelGenerate/MediaDevelGenerate.php

File

src/Plugin/DevelGenerate/MediaDevelGenerate.php, line 273

Class

MediaDevelGenerate
Provides a MediaDevelGenerate plugin.

Namespace

Drupal\media_entity\Plugin\DevelGenerate

Code

private function generateBatchMedia($values) {

  // Setup the batch operations and save the variables.
  $operations[] = [
    'devel_generate_operation',
    [
      $this,
      'batchPreGenerate',
      $values,
    ],
  ];

  // Add the kill operation.
  if ($values['kill']) {
    $operations[] = [
      'devel_generate_operation',
      [
        $this,
        'batchMediaKill',
        $values,
      ],
    ];
  }

  // Add the operations to create the media.
  for ($num = 0; $num < $values['num']; $num++) {
    $operations[] = [
      'devel_generate_operation',
      [
        $this,
        'batchCreateMediaItem',
        $values,
      ],
    ];
  }

  // Start the batch.
  $batch = [
    'title' => $this
      ->t('Generating media'),
    'operations' => $operations,
    'finished' => 'devel_generate_batch_finished',
    'file' => drupal_get_path('module', 'devel_generate') . '/devel_generate.batch.inc',
  ];
  batch_set($batch);
}