diff --git a/mappers/file.inc b/mappers/file.inc index 2cc5dc3..aa3acbb 100644 --- a/mappers/file.inc +++ b/mappers/file.inc @@ -20,11 +20,25 @@ function file_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_nam $info = field_info_field($name); if (in_array($info['type'], array('file', 'image'))) { - $targets[$name] = array( - 'name' => check_plain($instance['label']), + $targets[$name . ":uri"] = array( + 'name' => check_plain($instance['label']) . ': Uri', 'callback' => 'file_feeds_set_target', 'description' => t('The @label field of the node.', array('@label' => $instance['label'])), ); + if ($info['type'] == 'image') { + $targets[$name . ":alt"] = array( + 'name' => $instance['label'] . ': Alt', + 'callback' => 'file_feeds_set_target', + 'description' => t('The alt tag the @label field.', array('@label' => $instance['label'])), + 'real_target' => $name, + ); + $targets[$name . ":title"] = array( + 'name' => $instance['label'] . ': Title', + 'callback' => 'file_feeds_set_target', + 'description' => t('The title for the @label field.', array('@label' => $instance['label'])), + 'real_target' => $name, + ); + } } } } @@ -62,9 +76,10 @@ function file_feeds_set_target($source, $entity, $target, $value) { // Determine file destination. // @todo This needs review and debugging. + list($field_name, $sub_field) = explode(':', $target); 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); + $instance_info = field_info_instance($entity->feeds_item->entity_type, $field_name, $bundle_name); + $info = field_info_field($field_name); $data = array(); if (!empty($entity->uid)) { $data[$entity->feeds_item->entity_type] = $entity; @@ -73,22 +88,28 @@ function file_feeds_set_target($source, $entity, $target, $value) { // Populate entity. $i = 0; - $field = isset($entity->$target) ? $entity->$target : array(); + $field = isset($entity->$field_name) ? $entity->$field_name : array(); foreach ($value as $v) { - try { - $file = $v->getFile($destination); - } - catch (Exception $e) { - watchdog_exception('Feeds', $e, nl2br(check_plain($e))); - } - if ($file) { - $field['und'][$i] = (array)$file; - $field['und'][$i]['display'] = 1; // @todo: Figure out how to properly populate this field. - if ($info['cardinality'] == 1) { + switch ($sub_field) { + case 'alt': + case 'title': + $field[LANGUAGE_NONE][$i][$sub_field] = $v; break; - } - $i++; + case 'uri': + if ($file = $v->getFile($destination)) { + $file = (array) $file; + if (isset($field[LANGUAGE_NONE][$i])) { + $file = array_merge($file, $field[LANGUAGE_NONE][$i]); + } + $field[LANGUAGE_NONE][$i] = $file; + $field[LANGUAGE_NONE][$i]['display'] = 1; // @todo: Figure out how to properly populate this field. + } + break; + } + if ($info['cardinality'] == 1) { + break; } + $i++; } - $entity->{$target} = $field; + $entity->{$field_name} = $field; }