I need to import content from CSV to one of my content type which has one cck_time field.. I used feeds for importing content and i found a documentation for creating mapper of feeds for cck_time module here. I refered some other module mapper codes

http://drupal.org/node/856780

I used the code from cck phone module mapper

http://drupal.org/files/phone-feeds_1361084_2.patch

Finally i created a mapper code for cck_time but it shows only ' : ' without any data for cck_time field after importing.. i used the following code.

function cck_time_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('cck_time'))) {
      $targets[$name] = array(
        'name' => $instance['label'],
        'callback' => 'cck_time_feeds_set_target',
        'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
      );
    }
  }
}



/**
 * 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 cck_time_feeds_set_target($source, $entity, $target, $value) {
  if (!is_array($value)) {
    $value = array($value);
  }

  $info = field_info_field($target);

  // Iterate over all values.
  $i = 0;
  $field = isset($entity->$target) ? $entity->$target : array();
  foreach ($value as $v) {
    if (!is_array($v) && !is_object($v)) {
      $field['und'][$i]['value'] = $v;
    }
    
    if ($info['cardinality'] == 1) {
      break;
    }
    $i++;
  }
  $entity->{$target} = $field;
}

Please tell me what may be the issue?..

CommentFileSizeAuthor
#4 feedsD6Mapper-1443946-4.patch2 KBsydneyshan
#1 cck_time_feeds_1443946_1.patch1.72 KBAnonymous (not verified)

Comments

dhakshinait’s picture

Issue summary: View changes

extra information

Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new1.72 KB

Because of the presave function,the feeds mapper should actually provide hours, minutes, and meridiem values. Attached is a patch that works with both 12 and 24 hour fields.

dhakshinait’s picture

That patch works..Thanks a lot..

sydneyshan’s picture

Any chance of getting a D6 feeds mapper included in this module...?

sydneyshan’s picture

StatusFileSize
new2 KB

Scratch that - I've rolled one myself - hoorah!

This one is D6 compatible and rolled against the 2011-Feb-25 6.x-1.x-dev module.

sydneyshan’s picture

Issue summary: View changes

words correction