You are here

function filefield_node_import_values_alter in Node import 6

Implementation of hook_node_import_values_alter().

File

supported/filefield/filefield.inc, line 109
Support file for the CCK FileField module.

Code

function filefield_node_import_values_alter(&$values, $type, $defaults, $options, $fields, $preview) {
  foreach (node_import_cck_fields($type, 'filefield') as $fieldname => $fieldinfo) {
    $num_values = count($values[$fieldname]);
    if ($num_values > 0) {
      foreach (filefield_data_info() as $key => $datainfo) {
        $data_fieldname = node_import_cck_name($fieldname, 'data') . ':' . $key;
        $data_values = isset($values[$data_fieldname]) ? $values[$data_fieldname] : '';
        $data_values = is_array($data_values) ? $data_values : array(
          $data_values,
        );
        $data_values = $data_values + array_fill(count($data_values), $num_values, isset($defaults[$data_fieldname]) ? $defaults[$data_fieldname] : $fields[$data_fieldname]['default_value']);
        $data_values = array_slice($data_values, 0, $num_values);
        foreach ($values[$fieldname] as $i => $value) {
          if (!isset($values[$fieldname][$i]['data']) || !is_array($values[$fieldname][$i]['data'])) {
            $values[$fieldname][$i]['data'] = array();
          }
          $values[$fieldname][$i]['data'][$key] = $data_values[$i];
        }
      }
    }
  }
}