You are here

function _node_import_mapping in Node import 5

2 string references to '_node_import_mapping'
_node_import_options_validate in ./node_import.module
_node_import_start_validate in ./node_import.module

File

./node_import.module, line 244
This modules provides a wizard at "administer >> content >> import" to import a CSV file with nodes.

Code

function _node_import_mapping(&$edit) {
  $form = array();
  $form[] = array(
    '#type' => 'item',
    '#title' => t('File'),
    '#value' => $edit['filename'] . ' (' . format_size($edit['file']->filesize) . ') ',
  );
  $file_formats = _node_import_get_file_formats();
  $form[] = array(
    '#type' => 'item',
    '#title' => t('File format'),
    '#value' => $file_formats[$edit['file_format']],
  );
  $form[] = array(
    '#type' => 'item',
    '#title' => t('Type'),
    '#value' => node_get_types('name', $edit['type']),
  );
  if ($edit['type'] != 'node_import') {
    $fields = array_merge(array(
      '' => t('<none>'),
    ), node_import_fields($edit['type']));
    $function = $edit['file_format'];
    $headers = $function($edit['file']->filepath, TRUE);
    if (!$edit['match']) {
      if ($savedmatch = node_import_automap($edit['type'], $headers)) {
        $edit['match'] = $savedmatch;
      }
    }
    $j = 0;
    while (($row = $function($edit['file']->filepath)) && $j++ < 5) {

      // Make sure we have at least as many values as we have $headers.
      $row = array_slice(array_merge((array) $row, array_fill(count($row), count($headers), '')), 0, count($headers));
      foreach ($row as $i => $value) {
        $datatmp[$i][] = check_plain($value) . '&nbsp;';
      }
    }
    $form['match'] = array(
      '#tree' => TRUE,
      '#title' => t('Field mapping'),
      '#type' => 'fieldset',
      '#theme' => 'node_import_mapping_table',
    );
    foreach ($headers as $i => $value) {
      $form['match'][$i] = array(
        '#type' => 'select',
        '#title' => $value,
        '#default_value' => $edit['match'][$i],
        '#options' => $fields,
      );
    }
    foreach ((array) $datatmp as $i => $value) {
      $form['match'][$i]['#description'] = '<ul><li>' . implode('</li><li>', (array) $value) . '</li></ul>';
    }
  }
  $form[] = array(
    '#type' => 'submit',
    '#value' => t('Back'),
  );
  $form[] = array(
    '#type' => 'submit',
    '#value' => t('Next (options)'),
  );
  return $form;
}