You are here

function devel_generate_content_add_node in Devel 7

Same name and namespace in other branches
  1. 6 devel_generate.inc \devel_generate_content_add_node()

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

Parameters

$results: array of options obtained from devel_generate_content_form. If call this function directly, $results should contain at the very least: node_types => an associative array of node type machine names users => an array of UIDs title_length => max number of words in titles, for example 4.

2 calls to devel_generate_content_add_node()
devel_generate_batch_content_add_node in devel_generate/devel_generate_batch.inc
Batch API callback: Generate nodes.
devel_generate_content in devel_generate/devel_generate.inc
The main API function for creating content.

File

devel_generate/devel_generate.inc, line 652

Code

function devel_generate_content_add_node(&$results) {
  $node = new stdClass();
  $node->nid = NULL;

  // Insert new data:
  $node->type = array_rand($results['node_types']);
  node_object_prepare($node);
  $users = $results['users'];
  $node->uid = $users[array_rand($users)];
  $type = node_type_get_type($node);
  $node->revision = mt_rand(0, 1);
  $node->promote = mt_rand(0, 1);
  if (!$type || $type->has_title) {

    // We should not use the random function if the value is not random
    if ($results['title_length'] < 2) {
      $node->title = devel_create_greeking(1, TRUE);
    }
    else {
      $node->title = devel_create_greeking(mt_rand(1, $results['title_length']), TRUE);
    }
  }

  // Avoid NOTICE.
  if (!isset($results['time_range'])) {
    $results['time_range'] = 0;
  }
  devel_generate_set_language($results, $node);
  $node->created = REQUEST_TIME - mt_rand(0, $results['time_range']);

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

  // Populate all core fields on behalf of field.module
  module_load_include('inc', 'devel_generate', 'devel_generate.fields');
  devel_generate_fields($node, 'node', $node->type);

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