You are here

protected function ContentDevelGenerate::develGenerateContentAddNode in Devel 8

Same name and namespace in other branches
  1. 8.3 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentAddNode()
  2. 8.2 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentAddNode()
  3. 4.x devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentAddNode()

Create one node. Used by both batch and non-batch code branches.

2 calls to ContentDevelGenerate::develGenerateContentAddNode()
ContentDevelGenerate::batchContentAddNode in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php
ContentDevelGenerate::generateContent in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php
Method responsible for creating content when the number of elements is less than 50.

File

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

Class

ContentDevelGenerate
Provides a ContentDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

protected function develGenerateContentAddNode(&$results) {
  if (!isset($results['time_range'])) {
    $results['time_range'] = 0;
  }
  $users = $results['users'];
  $node_type = array_rand(array_filter($results['node_types']));
  $uid = $users[array_rand($users)];
  $node = $this->nodeStorage
    ->create(array(
    'nid' => NULL,
    'type' => $node_type,
    'title' => $this
      ->getRandom()
      ->sentences(mt_rand(1, $results['title_length']), TRUE),
    'uid' => $uid,
    'revision' => mt_rand(0, 1),
    'status' => TRUE,
    'promote' => mt_rand(0, 1),
    'created' => REQUEST_TIME - mt_rand(0, $results['time_range']),
    'langcode' => $this
      ->getLangcode($results),
  ));

  // A flag to let hook_node_insert() implementations know that this is a
  // generated node.
  $node->devel_generate = $results;

  // Populate all fields with sample values.
  $this
    ->populateFields($node);

  // See devel_generate_node_insert() for actions that happen before and after
  // this save.
  $node
    ->save();
}