You are here

function content_node_import_values_alter in Node import 6

Implementation of hook_node_import_values_alter().

File

supported/cck/content.inc, line 79
Support file for contrib CCK module.

Code

function content_node_import_values_alter(&$values, $type, $defaults, $options, $fields, $preview) {
  if (($node_type = node_import_type_is_node($type)) !== FALSE) {
    foreach ($fields as $fieldname => $fieldinfo) {
      if (isset($fieldinfo['cck:fieldname'])) {
        $values[$fieldinfo['cck:fieldname']] = array();
        $num_values = 0;
        foreach ($fieldinfo['cck:fieldinfo']['columns'] as $colname => $colinfo) {
          $cck_fieldname = node_import_cck_name($fieldinfo['cck:fieldname'], $colname);
          if (isset($values[$cck_fieldname])) {
            if (!is_array($values[$cck_fieldname])) {
              $values[$cck_fieldname] = array(
                0 => $values[$cck_fieldname],
              );
            }
            $num_values = max(count($values[$cck_fieldname]), $num_values);
          }
        }
        $i = 0;
        while ($i < $num_values) {
          $value = array();
          foreach ($fieldinfo['cck:fieldinfo']['columns'] as $colname => $colinfo) {
            $cck_fieldname = node_import_cck_name($fieldinfo['cck:fieldname'], $colname);
            if (isset($values[$cck_fieldname]) && array_key_exists($i, $values[$cck_fieldname])) {
              $value[$colname] = $values[$cck_fieldname][$i];
            }
            else {
              $value[$colname] = isset($defaults[$cck_fieldname]) ? $defaults[$cck_fieldname] : NULL;
            }
          }
          $values[$fieldinfo['cck:fieldname']][$i] = $value;
          $i++;
        }

        /*
                foreach ($fieldinfo['cck:fieldinfo']['columns'] as $colname => $colinfo) {
                  $cck_fieldname = node_import_cck_name($fieldinfo['cck:fieldname'], $colname);
                  unset($values[$cck_fieldname]);
                }
        */
      }
    }
  }
}