You are here

public function MediaDevelGenerate::batchCreateMediaItem in Devel 4.x

Same name and namespace in other branches
  1. 8.3 devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MediaDevelGenerate::batchCreateMediaItem()

Provides a batch version of createMediaItem().

Parameters

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

array $context: Batch job context.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.

\Drupal\Core\Entity\EntityStorageException Thrown if the bundle does not exist or was needed but not specified.

See also

self::createMediaItem()

File

devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php, line 368

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function batchCreateMediaItem(array $vars, &$context) {
  if ($this->drushBatch) {
    $this
      ->createMediaItem($vars);
  }
  else {
    $this
      ->createMediaItem($context['results']);
  }
  $context['results']['num']++;
}