You are here

function node_import_create in Node import 6

Create a new object of specified $type.

Parameters

$type: String. The node_import type.

$data: Array of data from the file as ($col_index => $value).

$map: Array of how the data maps to fields.

$defaults: Array of default values.

$options: Array of options.

$preview: Boolean.

Return value

The return value is: if $preview is TRUE, a string with the preview of the object is returned. If $preview is FALSE, an unique identifier is returned or an array with errors if failed.

2 calls to node_import_create()
node_import_add_form_submit_reload in ./node_import.admin.inc
node_import_do_task in ./node_import.inc
Import a number of rows from the specified task. Should only be called from within hook_cron() or from a JS callback as this function may take a long time.

File

./node_import.inc, line 1013
Public API of the Node import module.

Code

function node_import_create($type, $data, $map, $defaults, $options, $preview) {
  $output = $preview ? '' : array();

  // Reset execution time. Note that this only works when SAFE_MODE is OFF but
  // it has no side-effects if SAFE_MODE is ON. See
  // http://php.net/manual/en/function.set-time-limit.php
  set_time_limit(variable_get('node_import:set_time_limit', 60));
  $types = node_import_types();
  $fields = node_import_fields($type);

  // We need to clean out the form errors before submitting.
  form_set_error(NULL, '', TRUE);

  // Create a list of values to submit.
  $values = node_import_values($type, $data, $map, $defaults, $options, $fields, $preview);

  // Submit it for preview or creation.
  if (function_exists($function = $types[$type]['create'])) {
    $output = $function($type, $values, $preview);
  }
  module_invoke_all('node_import_postprocess', $type, $values, $options, $preview);

  // Check for errors and clear them again.
  if ($preview) {
    $output = theme('status_messages') . $output;
  }
  if ($errors = form_get_errors()) {
    if ($preview) {
      $output .= '<pre>values = ' . print_r($values, TRUE) . '</pre>';

      //TODO: show data instead?
    }
    else {
      $output = $errors;
    }
  }
  form_set_error(NULL, '', TRUE);
  drupal_get_messages(NULL, TRUE);

  // Otherwise they are still showed.
  return $output;
}