protected function ContentDevelGenerate::develGenerateContentAddNode in Devel 8.2
Same name and namespace in other branches
- 8.3 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentAddNode()
- 8 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentAddNode()
- 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 - Add node to existings batch operation.
- 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 498
Class
- ContentDevelGenerate
- Provides a ContentDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
protected function develGenerateContentAddNode(&$results) {
if (!isset($results['time_range'])) {
$results['time_range'] = 0;
}
$users = $results['users'];
$node_type = array_rand($results['node_types']);
$uid = $users[array_rand($users)];
$node = $this->nodeStorage
->create(array(
'nid' => NULL,
'type' => $node_type,
'title' => $node_type . '_' . $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' => $this->time
->getRequestTime() - 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_entity_insert() for actions that happen before and after
// this save.
$node
->save();
}