You are here

function _plupload_imagefield_import_create_node in Plupload integration 6

Create a new node with an attached image file. Largely copied from imagefield_import.

1 call to _plupload_imagefield_import_create_node()
plupload_imagefield_create_node_from in ./plupload.module
Helper wrapper around the cck code to create a node of this type. Largely copied from imagefield_import.module

File

./plupload.module, line 326

Code

function _plupload_imagefield_import_create_node($field, $form_state_values, $file = NULL, $options) {
  global $user;
  module_load_include('inc', 'node', 'node.pages');

  // Create a basic node object.
  $node = new stdClass();
  $node->type = $field['type_name'];
  $node->uid = $user->uid;
  $node->name = $user->name;
  $node->title = $form_state_values['title'];
  $node->body = $form_state_values['body'];
  node_object_prepare($node);

  // Add the image to the node object.
  $field_name = $field['field_name'];
  $node->{$field_name} = array(
    $file,
  );

  // Make it easy for other modules to add data to imported nodes using
  // hook_form_alter (see http://drupal.org/node/714550 for details).
  foreach (array_keys($options) as $key) {
    if (!isset($node->{$key})) {
      $node->{$key} = $options[$key];
    }
  }

  // Add any additional cck fields set during import.
  $type = content_types($field['type_name']);
  if (!empty($type['fields'])) {
    foreach ($type['fields'] as $name => $field) {
      if ($field['type'] != 'filefield') {
        $node->{$name} = $form_state_values[$name];
      }
    }
  }

  // Pretend we're saving the node from a node form to please modules like filefield_paths.
  $node->form_id = $node->type . '_node_form';
  $node = node_submit($node);
  module_invoke_all('plupload_node_presave', $node, $options);
  node_save($node);
  module_invoke_all('plupload_node_postsave', $node, $options);
  return $node;
}