It appears the actual FileField mapper in Feeds module supports Enclosures, but only SimplePie parser uses them. Anyone have an idea how difficult it would be to implement Enclosures in this module? Even just a rough idea to start with would be helpful. Thanks!

elizzle

Files: 
CommentFileSizeAuthor
#91 file.zip1.35 KBLeT
#86 feeds-alt_and_title-reroll-1080386-86.patch16.64 KBtwistor
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-reroll-1080386-86.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#80 feed_mapping.png21.83 KBjwmeyerson
#80 feeds_tamper.png17.25 KBjwmeyerson
#80 feeds_csv.png7.43 KBjwmeyerson
#80 feeds_outcome.png37.42 KBjwmeyerson
#80 mapping_file.txt3.79 KBjwmeyerson
#78 feeds-alt_and_title-reroll-1080386-78.patch4.43 KBasgorobets
FAILED: [[SimpleTest]]: [MySQL] 4,336 pass(es), 21 fail(s), and 0 exception(s).
[ View ]
#72 feeds-alt_and_title-reroll-1080386-72.patch3.87 KBtwistor
FAILED: [[SimpleTest]]: [MySQL] 3,900 pass(es), 21 fail(s), and 0 exception(s).
[ View ]
#71 Image for xml of multiple image with a caption22.16 KBElifas
#70 feeds-alt_and_title-reroll-1080386.patch3.56 KBmoonray
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-reroll-1080386.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#65 feeds-alt_and_title-1080386.patch3.34 KBslefevre1
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-1080386.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#62 feeds-alt_and_title-1080386-62.patch6.9 KBretiredpro
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in feeds-alt_and_title-1080386-62.patch.
[ View ]
#54 filefield.diff1.29 KBchadmkidner
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch filefield.diff. Unable to apply patch. See the log in the details link for more information.
[ View ]
#48 feed temper3.PNG21.25 KBbianchi
#46 feed temper.PNG66.17 KBbianchi
#46 feed temper2.PNG51.15 KBbianchi
#43 feeds-alt_and_title-1080386-43.patch3.22 KBAndyF
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-1080386-43.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#32 alt_title03.png35.41 KBdj1999
#32 alt_title02.png11.68 KBdj1999
#32 alt_title01.png72.76 KBdj1999
#17 feeds_1080386_17_title_and_alt_fields_and_multiple_files.patch1.16 KBrhouse
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds_1080386_17_title_and_alt_fields_and_multiple_files.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#2 feeds-filedescription.patch1.27 KBelizzle
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in feeds-filedescription.patch.
[ View ]
#5 feeds-filefield-description.patch1.24 KBelizzle
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in feeds-filefield-description_0.patch.
[ View ]

Comments

elizzle’s picture

Honestly, I'm just trying to find a way to import an image URL -> ImageField with an accompanying description.

elizzle’s picture

Title:Filefield description support» Support for Enclosures
Project:Feeds» Feeds JSONPath Parser
Version:6.x-1.0-beta10» 6.x-1.0-beta5
StatusFileSize
new1.27 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in feeds-filedescription.patch.
[ View ]

I was able to do it with a small hack to feeds module, specifically /feeds/mappers/filefield.inc ~ line 45 on latest beta10. It requires you to construct your feed with the file url and description in one field with a pipe delimiter IF you would like a description, otherwise it's business as usual.

EDIT: Use patch from #5.

elizzle

elizzle’s picture

Project:Feeds JSONPath Parser» Feeds
Version:6.x-1.0-beta5» 6.x-1.0-beta10
elizzle’s picture

Title:Support for Enclosures» Filefield description support
elizzle’s picture

StatusFileSize
new1.24 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in feeds-filefield-description_0.patch.
[ View ]

I didn't need an is_array check, and I was missing a closing bracket. Here is the updated version. ::sigh::

funkeyrandy’s picture

Title:Support for Enclosures» Filefield description support
Project:Feeds JSONPath Parser» Feeds
Version:6.x-1.0-beta5» 6.x-1.0-beta10

is there a patch for d7? i need the alt text and description to populate from a csv import

funkeyrandy’s picture

Priority:Normal» Critical

ive ported your code to d7...but what about multiple images? im trying to import like:

image.jpg|1rst image, image2.jpg|2nd image

funkeyrandy’s picture

Version:6.x-1.0-beta10» 7.x-2.0-alpha2
Category:feature» support

never mind....i figured it out....basically jsut exploded my import array by multiple dlimiters for the title and alt fields, and wrote to the $field['und'][$i]['title'] entity

funkeyrandy’s picture

Title:Filefield description support» How to get title and alt fields into your image import for drupal 7 feeds

Basically I just exploded my import array by multiple dlimiters for the title and alt fields, and wrote to the $field['und'][$i]['title'] entity

here is my file.inc modified code....use any delimiters in your file you want ;) someday it would be good to build a delimiter field choice into the field mapper....

<?php
// $Id: file.inc,v 1.1.2.3 2010/10/28 18:26:26 alexb Exp $

/**
 * @file
 * On behalf implementation of Feeds mapping API for file.module and
 * image.module.
 *
 * Does actually not include mappers for field types defined in fields module
 * (because there aren't any) but mappers for all fields that contain their
 * value simply in $entity->fieldname['und'][$i]['value'].
 */

/**
 * Implements hook_feeds_processor_targets_alter().
 *
 * @see FeedsNodeProcessor::getMappingTargets().
 */

function 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('file', 'image'))) {
     
$targets[$name] = array(
       
'name' => $instance['label'],
       
'callback' => 'file_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 file_feeds_set_target($source, $entity, $target, $value) {
  if (empty(
$value)) {
    return;
  }
 
module_load_include('inc', 'file');

 

// Make sure $value is an array of objects of type FeedsEnclosure.
 
if (!is_array($value)) {
 
$all=explode("|", $value);
 
   
$value= explode(",", $all[0]);
   
$titles = explode(">>", $all[1]);
       
$alt = explode("*", $all[2]);
  }
  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;
  }

 

// Determine 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 = file_field_widget_uri($info, $instance_info, $account);

 

// Populate entity.
 
$i = 0;
 
$field = isset($entity->$target) ? $entity->$target : array();
  foreach (
$value as $v) {
 
    if (
$file = $v->getFile($destination)) {
     
$field['und'][$i] = (array)$file;
       
$field['und'][$i]['title'] = $titles[$i];
        
$field['und'][$i]['alt'] = $alt[$i];
     
$field['und'][$i]['display'] = 1; // @todo: Figure out how to properly populate this field.
     
if ($info['cardinality'] == 1) {
        break;
      }
     
$i++;
    }
  }
 
$entity->{$target} = $field;
}
?>

my imagefield row in my csv looks like this:
sites/default/files/Montgomery-1.jpg,sites/default/files/Montgomery-2.jpg,sites/default/files/Montgomery-3.jpg|blahblahbl>>blahblah>>blah|at-1*at-2*alt-3

orangecoat-ciallella’s picture

@funkeyrandy , is there a syntax for uploading multiple files, via CSV, already built into the feeds file mapper? I know your code above is talking about adding alt and title tags to an image, but I'm just trying to upload multiple files.

I've tried setting the importer delimiter to ; and then using
"filepath1,filepath2"
"filepath1|filepath2"

but the CSV processor returns an error like my CSV has extra columns.

I ask because your example above appears to do comma separated multiple filepaths in one field. It's unclear if that is core functionality for the Feeds module, or another part of your patch.

Thanks

clanghoff’s picture

Please excuse my limited experience in these matters. Sorry if this is the wrong thread, but the issue seems to be tied to this process somehow.

I am trying to upload multiple images via CSV fields. I have implemented the code fix in #9 in this thread with some success. I have been able to upload multiple files into content nodes at times. However, I am randomly getting an error "no active batch" when I run the feed importer. I am stuck at this point, but occasionally something (goodness knows what) changes and I am able to run the importer again. Does anyone here know what the "no active batch" error mean and/or know how to fix it?

Thanks! everyone here has already been so much help with their posts.

funkeyrandy’s picture

yes..the commas were working by default...i just added pipes to be abe to explode the parts

Dave Reid’s picture

Priority:Critical» Normal

Support and feature requests are *never* critical. Please don't abuse the priority field.

dotman’s picture

I get an error like this when I am just trying to get one image and a title:

http://example.org/images/myimage.jpg|this is a title

So does this only work with multiple images? Is the alt required. No error with just the image path, but when i add the pipe and title, I get this:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=86&op=do StatusText: Service unavailable (with message) ResponseText: Recoverable fatal error: Argument 2 passed to token_replace() must be an array, null given, called in /Users/dotman/Sites/sandbox/modules/file/file.field.inc on line 581 and defined in token_replace() (line 79 of /Users/dotman/Sites/sandbox/includes/token.inc).

any ideas? i would like to get at least the title so I might be able to add it as a caption.

Edit: which file.inc file are you adding to, the feeds mapper of the system module? or both?

Dave Reid’s picture

@dotman: That "Recoverable fatal error: Argument 2 passed to token_replace()" bug has already been fixed in 7.x-1.x-dev.

dotman’s picture

thanks for getting back dave. i'm using the latest version of Feeds 7.x-2.x-dev, and I only get that error when I apply the patch funkyrandy applied to his file.inc mapper shown above.

any idea what in his code would cause that error? It would be nice to map to the title and alt tags. the multiple files isn't as important, but would be cool to have. BTW, thanks for all your and others hard work on this module. it's really appreciated.

Thanks.

rhouse’s picture

Version:7.x-2.0-alpha2» 7.x-2.0-alpha3
Priority:Normal» Critical
StatusFileSize
new1.16 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds_1080386_17_title_and_alt_fields_and_multiple_files.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

dotman @16, the reason it isn't going is that the latest feeds has some changes not included in funkeyrandy's excellent enhancement. I've done some bulletproofing on funkeyrandy's great work and made it into a patch on feeds-7.x-2.0-alpha4.

I have slightly changed funkeyrandy's syntax to make it a bit simpler:

  • Use comma-separated (real) csv file syntax
  • Separate the filenames from the titles from the alt fields with "|"
  • Separate individual files, titles, and alt fields with ";"

Example:

... ,sites/default/files/temp-uploads/alandra.jpg;sites/default/files/temp-uploads/whitewood.jpg|The Beautiful Alandra;Magnificent Whitewood|View of Alandra from the road;View of Whitewood from the hillside, ...

Tested, works. Attached.

dimitriseng’s picture

@ rhouse. Your solution in #17 looks great. Would you be able to provide the same also for D6 (filefield.inc)? #5 from elizzle is working ok for importing the image description, but it does not import the alt text and title. It also does not handle importing multiple images. Thank you.

TimelessDomain’s picture

Thank you for this rhouse. It works just as you describe.

i was originally thinking ,path/filename1;title1;alt2|path/filename2;title2;alt2, would be better for compiling a bunch of images for quick importing, but after thinking,

use the following rows in your table
- path/filename
- title
- alt

Then each column would be a different image.
after inputting them all -> export a CSV with a ; delimiters then combine the rows in a text program with the | symbol to split them. all good to go for importing@!
excel even has a row-> column flip so that would work here as well if your cells are the normal way (vertical instead of horizontal)

TimelessDomain’s picture

Status:Active» Needs review
dj1999’s picture

Hi,

this is an alternative but this does not handle multiple image fields. This is able to choose whitch csv columns are image alt and title data on processor mapping form.

This is the mappers/file.inc

<?php

/**
 * Implements hook_feeds_processor_targets_alter().
 *
 * @see FeedsNodeProcessor::getMappingTargets().
 */
function 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('file', 'image'))) {
           
$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,
                );
            }
        }
    }
}

function

file_feeds_set_target($source, $entity, $target, $value) {
    if (empty(
$value)) {
        return;
    }
   
module_load_include('inc', '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;
    }

   

// 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, $field_name, $bundle_name);
   
$info = field_info_field($field_name);
   
$data = array();
    if (!empty(
$entity->uid)) {
       
$data[$entity->feeds_item->entity_type] = $entity;
    }
   
$destination = file_field_widget_uri($info, $instance_info, $data);

   

// Populate entity.
   
$i = 0;
   
$field = isset($entity->$field_name) ? $entity->$field_name : array();
    foreach (
$value as $v) {
        switch (
$sub_field) {
            case
'alt':
            case
'title':
               
$field[LANGUAGE_NONE][$i][$sub_field] = $v;
                break;
            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->{$field_name} = $field;
}
?>

Regards,
Joe

dimitriseng’s picture

Hi, from #18:

@ rhouse. Your solution in #17 looks great. Would you be able to provide the same also for D6 (filefield.inc)? #5 from elizzle is working ok for importing the image description, but it does not import the alt text and title. It also does not handle importing multiple images. Thank you.

rhouse’s picture

Hi Dimitriseng,

Sadly I don't know how! :-( I am more of a Drupal plodder than a Drupal expert.

minneapolisdan’s picture

The patch at #17 works for me as well. I'm curious, however, if I also had a field for Documents, and wanted to include multiple values for those as well... Would I need to copy the contents of that patch, modify it for files instead of images, and then apply it too?

spoetnik’s picture

Applied patch #17 but it only imports the first image of a multiple image field (a gallery) Any thoughts whats wrong? How do you all use this patch?

This is the input for the field:

,"http://devwebsite.nl/sites/devwebsite.nl/files/Products/Kites/devwebsite-img-145-2.jpg|Title of the image|Alt of the image;http://devwebsite.nl/sites/devwebsite.nl/files/Products/Kites/devwebsite-img-145-3.jpg|Title of the image|Alt of the image;http://devwebsite.nl/sites/devwebsite.nl/files/Products/Kites/devwebsite-img-145-4.jpg|Title of the image|Alt of the image;http://devwebsite.nl/sites/devwebsite.nl/files/Products/Kites/devwebsite-img-145-5.jpg|Title of the image|Alt of the image;http://devwebsite.nl/sites/devwebsite.nl/files/Products/Kites/devwebsite-img-145-6.jpg|Title of the image|Alt of the image;http://devwebsite.nl/sites/devwebsite.nl/files/Products/Kites/devwebsite-img-145-7.jpg|Title of the image|Alt of the image",

tonkatuph’s picture

how do we patch?

rhouse’s picture

@spoetnik, The order my patch works is: All the filenames, all the alts, all the titles. You have file-alt-title, file-alt-title ...
Also try it without quotes around the whole thing.
Ron

chrisjlee’s picture

@tonkatuph You'll find your answer here: http://drupal.org/patch

sanguis’s picture

subscribing

7wonders’s picture

Just found this - http://drupal.org/sandbox/eosrei/1315294 - which means you could just create some dummy fields on your content type to import the alt and title of your choosing to and then let that module do the rest using tokens.

dotman’s picture

@dj1999, I just ran your alt and title mapper and mapped a field in my csv to the Image: title and Image:alt, but when I review an article after import, none of those fields are populated. can you confirm this works for you? Is there a character limit on those fields?

thanks.

dj1999’s picture

StatusFileSize
new72.76 KB
new11.68 KB
new35.41 KB

@dotman, yes I can confirm it works fine for me. I did not take any limitations, but I do not know that system make some limitations or not.
Here is some picture from csv, feeds mapper and result.

dotman’s picture

ok, it does seem to work. apparently there is a character limit of i think 128 in d7 for title and alt. Have you run into this? i've been following this thread here for patching core to resolve this, as i'm trying to use a caption module that takes the title tag and formats a caption for the image. wondering if you hav any insight into this.

http://drupal.org/node/1015916#comment-5335994

thanks.

febbraro’s picture

Priority:Critical» Normal

Needs review, but certainly is not critical.

quantumized’s picture

I have the same issue after applying path #17 only the first image is imported, the others are ignored.

kpv’s picture

#17 thanks

maomaohuhu’s picture

#21 worked great for me, thanks ! (applied on top of feeds-7.x-2.0-alpha4 )
NB: I don't think the ending php tag should be there tho.

Summit’s picture

Hi, #21 also great for me.
Greetings, Martijn

FiNeX’s picture

Using #21 with Feeds tamper module allows to configure the "Explode" feature in order to import multiple images in the same field.

Example:

The CSV could be something like:

"uri","alt","title"
"/path/img1.jpg|/path/img2.jpg","alt text 1|alt text 2","Title 1|Title 2"

And the Feeds tamper have to be configured on the three fields with the explode filter using the "|" (pipe) char.

chrisjlee’s picture

So is this going to be rolled into feeds 2.0?

Or is the drupal way eventually going to utilize the aftorementioned synchronize image title sandbox module?

chadmkidner’s picture

Version:7.x-2.x-dev» 7.x-2.0-alpha3
Category:feature» support
Status:Needs work» Needs review

I am trying to apply the original mapper concept in #5 for D6 as it appears the rest of the discussion has moved toward D7. I am trying to use it for title and alt though not the description.. I thought this should have been fairly easy as they're all an image sub-field under [data]. I've made small changes hoping to map just the value, title, and alt but the best result I have come up with ONLY imports the image and title but ignores the alt.. Any Ideas??

Heres the complete function with the most recent alterations I've made.

I was able to get this working, I'm updating the code below with what is working for me in D6. Hope it can help anyone else using D6.

function filefield_feeds_set_target($node, $field_name, $value) {
  // Normalize $value, create an array of FeedsEnclosures of it.

  $valueData = explode("|", $value); // pipe as delimiter to seperate value, title, and alt. Any delimiter can be used.
  $alt = $valueData[2]; // alt text as last value
  $title = $valueData[1]; // title text as second value
  $value = $valueData[0]; // value as first value

    $enclosures = array();
  if (!is_array($value)) {
    $value = array($value);
  }
  foreach ($value as $k => $v) {
    if ($v instanceof FeedsEnclosure) {
      $enclosures[] = $v;
    }
    elseif (valid_url($v)) {
      $enclosures[$k] = new FeedsEnclosure($v, 'application/octet-stream');
    }
  }

  // Map enclosures. Works with Title and Alt Tags
  $items = isset($node->$field_name) ? $node->$field_name : array();
  foreach ($enclosures as $enclosure) {
    if ($file = $enclosure->getFile()) {
      $field = content_fields($field_name, $node->type);
      $target_dir = filefield_widget_file_path($field, user_load($node->uid));
      $info = field_file_save_file($enclosure->getFile(), array(), $target_dir);
      if ($info) {
        $info['list'] = array();
        $info['data']['alt'] = $alt; // mapping for alt text
        $info['data']['title'] = $title;  // mapping for title text
        if ($field['list_field']) {
          $info['list'] = $field['list_default'];
        }
        $items[] = $info;
        $error = FALSE;
      }
    }
  }
  $node->$field_name = $items;
}

1mundus’s picture

Is #21 commited in the current dev version for Drupal 7? I use recommended release (alpha5) plus that code and it seems to work perfectly. However, I'd prefer to use it in the official release, since there are thousands of nodes that I have to import and don't want to take a risk that this code breaks something else.

AndyF’s picture

Version:7.x-2.0-alpha3» 7.x-2.x-dev
Category:support» feature
Status:Needs review» Reviewed & tested by the community
StatusFileSize
new3.22 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-1080386-43.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I've rolled #21 against the latest and included the changes from ea36f8b (the only commit on mappers/file.inc since the snippet was posted). It works for me (including for multiple images if using feeds tamper and explode). Marking as RTBC considering my experience and #39, #38, #37, and #32. I haven't looked through the code myself (I'm a beginner to Feeds development). Thanks!

twistor’s picture

Status:Reviewed & tested by the community» Needs work

Looks good.

  1. The tests should be updated to include the new targets.
  2. The description of the uri target should have the word uri in it.

And why do we only check for cardinality == 1? I know that's a common pattern, but it strikes me as odd.

bianchi’s picture

Hello Guys,

Is the separator equal to ":" ?

I saw from :
list($field_name, $sub_field) = explode(':', $target);

I have tried with pipe, and it's not working, I get 404 error from the server.

Line :
"http://lnet-svr-apch/stevesommerfeld/images/stories/clock.jpg<strong>|</strong>http://lnet-svr-apch/stevesommerfeld/images/stories/bike.jpg"

Result :
Download of http://lnet-svr-apch/stevesommerfeld/images/stories/clock.jpg|http://lnet-svr-apch/stevesommerfeld/images/stories/bike.jpg failed with code 404.

Any suggestions guys ?

bianchi’s picture

StatusFileSize
new51.15 KB
new66.17 KB

Is this the right feed temper ?

bianchi’s picture

Title:How to get title and alt fields into your image import for drupal 7 feeds» Some impressionist abstract painting
StatusFileSize
new21.25 KB

Done with feed tamper,
thanks a lot guys :)

TimelessDomain’s picture

Title:Some impressionist abstract painting» How to get title and alt fields into your image import for drupal 7 feeds
MrPeanut’s picture

For what it's worth, the code from #21 works for me.

suegmune’s picture

Please update this for files with description too! :)

bneil’s picture

Version:7.x-2.0-alpha3» 7.x-2.x-dev
Category:support» feature
Status:Needs review» Needs work

The patch in #43 worked for me.

AlfTheCat’s picture

Has anyone had any luck with D6? I tried #5 but the patch no longer works. I alo modified filefield.inc to reflect #41 but I see no changes at all (using the latest dev release.)

Using tokens, the alt and title texts are not saved when using feed imports.

Is there no way at all to get alt texts and title texts enclosed when importing nodes from csv with feeds in D6?

chadmkidner’s picture

StatusFileSize
new1.29 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch filefield.diff. Unable to apply patch. See the log in the details link for more information.
[ View ]

@AlfTheCat Here's a diff file from the actual file I use. Note I use "*" as my deliminator, you can change this to whatever you plan to use in your flat file. For obvious reasons you probably don't want to use a comma unless your file is tabbed.

prakashrajavel’s picture

prakashrajavel’s picture

thanks its working well

AlfTheCat’s picture

@prakashrajavel, would you be willing to detail more on how you got this to work?
I simply applied the diff patch but I don't get any alt or title desciption destinations in my mapping settings.

Hope you can help me out!

Thanks.

AlfTheCat’s picture

retiredpro’s picture

Can we get the patch from #43 re-rolled for the latest dev? I had a Hunk #3 failed error when trying to patch. Thanks!

retiredpro’s picture

I was able to get it to work by manually editing my file according to the patch. Import works if I have an image for each row but will error out on rows without any image filenames.

I get the error "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null" and those rows will not import.

AndyF’s picture

@retiredpro I get that if I leave out the Image: Uri component, but try to import Image: Alt: maybe something's similar in your case? (sorry that's exactly what you've written in your post, it must be too early!) Btw, if you've manually applied to patch, could you reroll an up-to-date one?

retiredpro’s picture

StatusFileSize
new6.9 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in feeds-alt_and_title-1080386-62.patch.
[ View ]

@andy, attached my edits. not sure why, but i try to follow the steps for creating a patch (http://drupal.org/project/feeds/git-instructions) it just subtracts all of the previous code and re-adds my entire file instead of efficiently adding and subtracting the changes.

Also, my errors came from rows that had alt descriptions and no uri values. My bad. Thanks for your help!

lquessenberry’s picture

Hey guys! Nice work in the past few months. I am wondering if someone would be willing to give a detailed outline of the versions, patches, and methodologies used to properly import images with Alts and Titles on multiple image instance fields. If someone even maybe has a successfully patched version of feeds that they'd be willing to share, I would appreciate that greatly.

My situation is that I need to be able to map several images with Alts and Titles to one field from a Postgres DB. We tried many of the suggestions above and were short on success, but it seems that you guys are getting it to work. Fortunately, if there is a need to prepare or clean the data and set it up in a certain format prior to mapping it in feeds, we have the ability to mold our data to fit a certain criteria of columns and arrange them to be in a certain format.

I look forward to seeing what you guys come up with, and for those of us having trouble with making patches, or for those of us who aren't great with applying patches, would it hurt to send us a compiled version of feeds with successful patches rolled in? I'd be willing to take one privately as well. If there is anything I can do to help, I will.

Thanks!

AndyF’s picture

retiredpro wrote:

not sure why, but i try to follow the steps for creating a patch (http://drupal.org/project/feeds/git-instructions) it just subtracts all of the previous code and re-adds my entire file instead of efficiently adding and subtracting the changes.

I haven't checked, but that's probably line endings. Try configuring your editor to use *nix line endings.

lquessenberry wrote:

We tried many of the suggestions above and were short on success, but it seems that you guys are getting it to work.

What happened when you tried to apply the patch from #62? Did it apply? Did the new targets appear?

slefevre1’s picture

StatusFileSize
new3.34 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-1080386.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

The patch in #62 did not seem to respect line endings and had wholesale replacements for blocks of code. This patch changes has the same result, but only changes the lines that are different.

lquessenberry’s picture

I am going to try the Patch in 65 and get back with you. What I really need to know is if the patches here will allow multiple Title and Alt values to be stored into a single image field.

lquessenberry’s picture

The patch in 65 worked for me, but I have not tested it for multiple images yet. I will report back unless someone can tell me that it is working for multiple images in one field.

afeijo’s picture

I also confirm that Patch #65 works, including for multiple images :D

Thanks a lot, you guys saved my neck. This was driving me crazy.

BTW, I used it with success with a XML source, not CSV.

moonray’s picture

The patch in #65 breaks the fixes made in http://drupalcode.org/project/feeds.git/commitdiff/9e89fdf

moonray’s picture

Status:Needs work» Needs review
StatusFileSize
new3.56 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-reroll-1080386.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Attached patch takes the patch from #65 and re-implements the fixes of above commit.

Elifas’s picture

Ok.. this is all fine and food for the CSV people.. what about me... im using xml to import multiple images from an old CMS and some of the images have captions.... My work around is to have image token field read from a field called

.... thsi works.. but all the images have different captions but feeds treats at the
field as one... meaning there will be 3 caption for each image.... is there a way ii can separate them? or in the xml is there a way i can perhaps make an attribute alt eg and have the image field get the contents of the alt attribute to be parsed into the alt field? My apologetic if this is the wrong node to bring this up.

Bellow is the image example of my issue :

first image is the way im currently importing and the highlighted is the alternative way of thinking to get captions from the attribute "alt" in the xml and not from the caption tag which i created a field and hhave mapped....

Myb im missing a small point but my head is now in overdrive!

twistor’s picture

StatusFileSize
new3.87 KB
FAILED: [[SimpleTest]]: [MySQL] 3,900 pass(es), 21 fail(s), and 0 exception(s).
[ View ]

#70 is a good start. For one, the patch needs to be created from Feeds root, not the mappers directory.

I have updated some things, to make it more inline with how mappers look today. If I can get a quick review, I'll push it.

moonray’s picture

Status:Needs review» Needs work

Testing it out, it turns out the following line returns an object, not a string:
$field[LANGUAGE_NONE][$delta][$sub_field] = $v;

To make it work without throwing notices (and not exceed the 512 field character limit):
$field[LANGUAGE_NONE][$i][$sub_field] = substr($v->getValue(), 0, 512);

Elifas’s picture

Guys is there an alternative way to patch with out drush??

twistor’s picture

#73, can I get more info on your setup? It's possible that it's getting an object, but that's definitely not the normal case.

moonray’s picture

These are feeds coming in from an RSS feed, so xml format.

Earlier in the function every $v that is not yet an object is turned into one; so yes, we do always get an object:

  foreach ($value as $k => $v) {
    if (!($v instanceof FeedsEnclosure)) {
      if (is_string($v)) {
        $value[$k] = new FeedsEnclosure($v, file_get_mimetype($v));
      }
      else {
        unset($value[$k]);
      }
    }
  }
FreeFox’s picture

Hi,

I noticed a bug in the patch. Near the end there is a line like this:

$field[LANGUAGE_NONE][$delta] += (array) $file;

This should be:

$field[LANGUAGE_NONE][$delta] .= (array) $file;

Than, when I try the patch #70 I get this error:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null

After reverting to version alpha7 the image import runs smoothly but without alt & title field ofcourse :(

I tried to find the culprit but my PHP knowledge is not that good to pinpoint the error. I'm available for more detailed info is needed.

asgorobets’s picture

Status:Needs work» Needs review
StatusFileSize
new4.43 KB
FAILED: [[SimpleTest]]: [MySQL] 4,336 pass(es), 21 fail(s), and 0 exception(s).
[ View ]

Hi guys,

According to #77:
It looks like using += is correct here:

<?php
$field
[LANGUAGE_NONE][$delta] += (array) $file;
?>

Since we want to preserve old fields and merge array values in case some of them already exist. But the error occurred when the array is not initialized.

Adding this would solve the problem:

<?php
$field
[LANGUAGE_NONE][$delta] = isset($field[LANGUAGE_NONE][$delta]) ? $field[LANGUAGE_NONE][$delta] : array();
?>

According to #73:
Not sure why you try to limit the field by 512 chars, but your are right, the $v in our case is always a FeedsEnclosure object, as pointed in #76, it looks like we'll have to move that portion of code in the switch structure under 'uri', because it's useless for 'alt' and 'title' fields.

But for now here is a reroll including mentioned fixes. This should work for those who search for a quick patch to get their work done.

P.S. Tested with multivalued fields and 2 mappings order: URI -> Title -> Alt and Title -> Alt -> URI.

moonray’s picture

From what I remember, the alt and/or title field in the DB is limited in number of characters. The DB handler throws notices for longer ones that they got trimmed.

EDIT: To be fair, I only got too long strings when the object got cast to a string and stored in the DB, so I'm not sure if many people will encounter the limit with the bug fixed.

jwmeyerson’s picture

Status:Needs work» Needs review
StatusFileSize
new3.79 KB
new37.42 KB
new7.43 KB
new17.25 KB
new21.83 KB

After testing several of the patches and rerolls above - I'm running into what I think must be an oversight on my end.
My feeds mapper now allows for several targets (Image:Uri, Image:Alt, and Image:Title), all of which I attach to the Image source.
My csv uses | to separate the image from the alt and the title, such that fields in my image column within the CSV looks like this:

image/uri/image2.jpg|alttext|titletext

I have Feeds Tamper setup on the Image->Uri, Alt, Title with the Explode plugin and I am using the | delimiter.
I only have one image per node - no need for multiple images, just trying to get alt and title for every image to import.
The importer successfully creates the nodes, but the alt and title sub-fields are filled with the Uri.
So, the outcome is all other sources are successfully mapped, including the image itself (which shows up beautifully) but then the alt and title sub-fields are populated by the uri ant not the actual alttext and titletext values.

Has anyone else experienced this? I've attached screenshots of my setting and my file.inc

EDIT: I got them to work - I just had to create three different sources/csv fields...Image: Uri, Image: Title, and Image: Alt instead of mapping the same source (Image) to three different targets and trying to use tamper->explode plugin to explode the array of targets into the three fields associated with Image.

Status:Needs review» Needs work

The last submitted patch, feeds-alt_and_title-reroll-1080386-78.patch, failed testing.

Summit’s picture

Status:Needs review» Needs work

Hi,
I would like to get to work with one field filling all three targets: Image: Uri, Image: Title, and Image: Alt instead of mapping the same source (Image) to three different targets and trying to use tamper->explode plugin to explode the array of targets into the three fields associated with Image.
Will this also be possible please?
greetings,
Martijn

redndahead’s picture

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, feeds-alt_and_title-reroll-1080386-78.patch, failed testing.

RajeevK’s picture

I used #78 & it's working for me .

But when I import data I get some error/warning, it looks like --

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null

What can be the problem ?

Thanks.

twistor’s picture

Status:Needs work» Needs review
StatusFileSize
new16.64 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-alt_and_title-reroll-1080386-86.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Ok, this should be close to ready.

twistor’s picture

Version:7.x-2.x-dev» 7.x-1.x-dev
Status:Needs review» Patch (to be ported)
twistor’s picture

Title:How to get title and alt fields into your image import for drupal 7 feeds» Add mapping for title and alt fields on images.
MegaChriz’s picture

Version:7.x-1.x-dev» 6.x-1.x-dev

@twistor
I think you meant it should be ported to 6.x-1.x. Changing accordingly.

aubjr_drupal’s picture

Status:Patch (to be ported)» Needs work

This isn't fixed and shouldn't be ported to the release version of Feeds yet. I'm using XPath Parser XML.

This feed import was working right before upgrading to the -dev version (was using latest release). I just updated to the latest -dev version to pull in alt/title values as well, and I just ran into the SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null problem.

I'm doing an import of directory people and pulling in images/files. Shortened example of the XML structure:

<person><fullName>John Doe</fullName><imgURL>http://localhost/imgDir/img1.jpg</imgURL>...<moreFields>...</person>

The imgURL XML node is mapped to Picture:URI. The fullName XML node is mapped to Picture:Alt. (I didn't use Picture:Title at all.)

I do see a pattern on which nodes are getting the error. Every person XML node had a fullName value (never empty). Not every imgURL XML node has a value, though. The three person nodes of the 50 that did not have any value in imgURL got the error.

I haven't looked at the patch, but I bet that's the problem - the code isn't checking to be sure there's a URI before assuming there's a place for the alt to go? It wouldn't surprise me if the same problem comes up with a non-empty Picture: Title XML node with an empty Picture: URI XML node.

(Sidenote: When I installed the -dev version, I had to delete the mapping for "Picture" and re-add it as "Picture: URI".)

EDIT: I had planned on using the Picture field using an uploaded default image when no img URL was available in the XML feed.

LeT’s picture

Assigned:Unassigned» LeT
Category:feature» task
StatusFileSize
new1.35 KB

Modified file.inc at #9 for importing multiple files with descriptions as well. Works in Drupal 7.

Used the following CSV format:
"path/file1.doc;path/file2.doc | File description 1; File description 2"

The separators I have used are semi-colons in the patch. Make sure files are loaded to server in a temporary folder so "path" is the relative path to the folder where the images/files are located.

Summit’s picture

Hi Does this also work with images?
I have problem with this..
Greetings,Martijn

ecksley’s picture

I am a modestly competent patcher, and this isn't working for me. Something about "can't find file to patch at input line 5." I'm sure it's my fault.

That said, I offer a hack alternative for those who need this feature.

In my case I want my 'alt' and 'title' text to be the same as my 'node title.'
1.) Install rules and write an action like this:
EVENT
-Before Saving content

CONDITION
-Content is Type: Choose your type, this is optional
-Entity has field: Choose your field, this is optional

ELEMENTS
-Execute custom PHP code

$node->field_your_image[und][0][alt] = $node->title;
$node->field_your_image[und][0][title] = $node->title;

-Save Entity

2.) Install Feeds
-Set up and run your import
-your done, rules will map the alt and title fields automatically.

Afterwards you should disable the rule until next time.

If you require more granular control of your 'alt' and 'title' text you could create CCK fields for the feeds import. Then use your rule to match your actual 'alt' and 'title' fields to the ones used in the import. Drop the fields when you done or keep 'em and suppress their display.

I know. It's hack, but it works.

bisscomm’s picture

Any update on this?
This error still persists on latest dev version when importing:
SQLSTATE[23000]...

dvl’s picture

The last submitted patch, 17: feeds_1080386_17_title_and_alt_fields_and_multiple_files.patch, failed testing.

The last submitted patch, 86: feeds-alt_and_title-reroll-1080386-86.patch, failed testing.

  • twistor committed fce13c2 on 7.x-2.x authored by vinmassaro
    Issue #2341407 by vinmassaro, twistor: Fix missing file/image mappings...

  • twistor committed 0f9f84c on 7.x-2.x
    Issue #2341407 by vinmassaro, twistor: Fix missing file/image mappings...