diff --git a/mappers/faqfield.inc b/mappers/faqfield.inc new file mode 100755 index 0000000..27a60b7 --- /dev/null +++ b/mappers/faqfield.inc @@ -0,0 +1,93 @@ + $instance) { + $info = field_info_field($name); + if (in_array($info['type'], array('faqfield'))) { + $targets[$name] = array( + 'name' => check_plain($instance['label']), + 'callback' => 'faqfield_feeds_set_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + ); + } + } +} + +/** + * Callback for mapping faqfield fields. + */ +function faqfield_feeds_set_target($source, $entity, $target, $value) { + + if (empty($value)) { + return; + } + + // Make sure $value is an array of objects of type FeedsEnclosure. + if (!is_array($value)) { + $value = array($value); + } + + // Get the imput format, we're using it + if (isset($source->importer->processor->config['input_format'])) { + $format = $source->importer->processor->config['input_format']; + } + + $info = field_info_field($target); + + // Iterate over all values. + $field = isset($entity->$target) ? $entity->$target : array('und' => array()); + + // Allow for multiple mappings to the same target. + $delta = count($field['und']); + + foreach ($value as $v) { + + if ($info['cardinality'] == $delta) { + break; + } + + // Unsure if this does anything + $field['und'][$delta]['value'] = $v; + + // Parsing using the default faqfield theme, theme_faqfield_formatter + // This will need to change if faqfield theme ever changes. + $data = split('
', $v); + $data[0] = strip_tags($data[0]); + $data[1] = rtrim($data[1], '
'); + + // Set the newly seperated and cleaned fields + $field['und'][$delta]['question'] = $data[0]; + $field['und'][$delta]['answer'] = $data[1]; + + // Set the answer's format appropriately + if (isset($format)) { + $field['und'][$delta]['answer_format'] = $format; + } + + $delta++; + + } + + $entity->$target = $field; +} + +