fieldname['und'][$i]['value']. */ /** * Implements hook_feeds_processor_targets_alter(). * * @see FeedsNodeProcessor::getMappingTargets(). */ function _commerce_file_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { $info = field_info_field($name); if (in_array($info['type'], array('commerce_file', 'image'))) { $targets[$name] = array( 'name' => $instance['label'], 'callback' => 'commerce_file_feeds_set_target', 'description' => t('The @label field of the node.', array('@label' => $instance['label'])), ); } } } function commerce_file_field_widget_uri($field, $instance, $account = NULL) { $destination = trim($instance['settings']['file_directory'], '/'); // Replace tokens. $data = array('user' => isset($account) ? $account : $GLOBALS['user']); $destination = token_replace($destination, $data); return $instance['settings']['uri_scheme'] . '://' . $destination; } /** * Callback for mapping. Here is where the actual mapping happens. * * When the callback is invoked, $target contains the name of the field the * user has decided to map to and $value contains the value of the feed item * element the user has picked as a source. */ function commerce_file_feeds_set_target($source, $entity, $target, $value) { if (empty($value)) { return; } module_load_include('inc', 'commerce_file'); // Make sure $value is an array of objects of type FeedsEnclosure. if (!is_array($value)) { $value = array($value); } /* foreach ($value as $k => $v) { if (!($v instanceof FeedsEnclosure)) { if (is_string($v)) { $value[$k] = new FeedsEnclosure($v, 'application/octet-stream'); } else { unset($value[$k]); } } } */ if (empty($value)) { return; dpm($value); } // Determine commerce_file destination. // @todo This needs review and debugging. list($entity_id, $vid, $bundle_name) = entity_extract_ids($entity->feeds_item->entity_type, $entity); $instance_info = field_info_instance($entity->feeds_item->entity_type, $target, $bundle_name); $info = field_info_field($target); $account = !empty($entity->uid) ? user_load($entity->uid) : NULL; $destination = commerce_file_field_widget_uri($info, $instance_info, $account); // Populate entity. $i = 0; $field = isset($entity->$target) ? $entity->$target : array(); foreach ($value as $v) { # if ($commerce_file = $v->getFile($destination)) { $commerce_file = file_load($v); $field['und'][$i] = (array)$commerce_file; # $field['und'][$i]['display'] = 1; // @todo: Figure out how to properly populate this field. $field['und'][$i]['data'] = array(); // @todo: Figure out how to properly populate this field. # $field[LANGUAGE_NONE][$i]['fid'] = $v; if ($info['cardinality'] == 1) { break; } $i++; # } } $entity->{$target} = $field; }