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?..
Comments
Comment #0.0
dhakshinait commentedextra information
Comment #1
Anonymous (not verified) commentedBecause 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.
Comment #2
dhakshinait commentedThat patch works..Thanks a lot..
Comment #3
sydneyshan commentedAny chance of getting a D6 feeds mapper included in this module...?
Comment #4
sydneyshan commentedScratch 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.
Comment #4.0
sydneyshan commentedwords correction