function ContentDevelGenerate::generateContent

Same name in other branches
  1. 8.x-1.x devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::generateContent()
  2. 5.x devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::generateContent()

Generate content when not in batch mode.

This method is used when the number of elements is under 50.

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

File

devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php, line 401

Class

ContentDevelGenerate
Provides a ContentDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

private function generateContent($values) {
    $values['node_types'] = array_filter($values['node_types']);
    if (!empty($values['kill']) && $values['node_types']) {
        $this->contentKill($values);
    }
    if (!empty($values['node_types'])) {
        // Generate nodes.
        $this->develGenerateContentPreNode($values);
        $start = time();
        $values['num_translations'] = 0;
        for ($i = 1; $i <= $values['num']; $i++) {
            $this->develGenerateContentAddNode($values);
            if (isset($values['feedback']) && $i % $values['feedback'] == 0) {
                $now = time();
                $options = [
                    '@feedback' => $values['feedback'],
                    '@rate' => $values['feedback'] * 60 / ($now - $start),
                ];
                $this->messenger()
                    ->addStatus(dt('Completed @feedback nodes (@rate nodes/min)', $options));
                $start = $now;
            }
        }
    }
    $this->setMessage($this->formatPlural($values['num'], 'Created 1 node', 'Created @count nodes'));
    if ($values['num_translations'] > 0) {
        $this->setMessage($this->formatPlural($values['num_translations'], 'Created 1 node translation', 'Created @count node translations'));
    }
}