function MediaDevelGenerate::generateMedia

Same name in other branches
  1. 5.x devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MediaDevelGenerate::generateMedia()

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

Parameters

array $values: Array of values submitted through a form.

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.

1 call to MediaDevelGenerate::generateMedia()
MediaDevelGenerate::generateElements in devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php
Business logic relating with each DevelGenerate plugin.

File

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

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

protected function generateMedia(array $values) {
    if (!empty($values['kill']) && $values['media_types']) {
        $this->mediaKill($values);
    }
    if (!empty($values['media_types'])) {
        // Generate media items.
        $this->preGenerate($values);
        $start = time();
        for ($i = 1; $i <= $values['num']; $i++) {
            $this->createMediaItem($values);
            if (isset($values['feedback']) && $i % $values['feedback'] == 0) {
                $now = time();
                $this->messenger()
                    ->addStatus(dt('Completed !feedback media items (!rate media/min)', [
                    '!feedback' => $values['feedback'],
                    '!rate' => $values['feedback'] * 60 / ($now - $start),
                ]));
                $start = $now;
            }
        }
    }
    $this->setMessage($this->formatPlural($values['num'], '1 media item created.', 'Finished creating @count media items.'));
}