Maybe I was totally missing the obvious but I could not figure out how to break up a set of tags on a node import so that they would be imported as say "Tag1", "Tag2", "Tag3" and not "Tag1, Tag2, Tag3" ie one tag and not three.
http://drupal.org/node/957654
This thread left me thinking there was not a way to do this? But the code seem to offer a chance to pass an array of terms.
I decided to use the || double pipe as the separator and see if this small amount of code would make that work.
// Handle non-multiple values.
if (!is_array($terms)) {
if (strpos($terms, '||') !== 0){
$terms = explode("||", $terms);
} else {
$terms = array($terms);
}
}
in taxonomy.inc on line 70 of that file in the mappers folder.
It did work so far but I did not do a ton of testing.
And it would be ideal to offer mapping options.
Attached is a patch to make this work but maybe it is not worth it? I mean maybe I was suppose to use some other format for this type of import?
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | multi-tag-import-1039134-4235274.patch | 440 bytes | mukhsim |
| #8 | feeds_taxonomy_mapper_split_terms.patch | 448 bytes | mindgame |
| patch_taxonomy_inc_multi_tag.patch | 526 bytes | yurtboy |
Comments
Comment #1
ropaolle commentedSubscribe
Comment #2
TrevorG commentedUnfortunately, this is exactly what I need and it doesn't work here.
I am importing a CSV with a field "tags" which looks like "tag1,tag2,tag3" .
After changing over to your version, it is still importing the tags as "tag1,tag2,tag3" instead of imploding them to "tag1" "tag2" "tag3" . Unfortunately I know little PHP so I won't be much help. thanks for trying!
edit: http://drupal.org/node/925264 appears to be the place where Alex committed this change for the 6.x version. Since I don't have 6.x I can't determine one way or the other. Either way, all users of this module need a way to import multiple tags at once with a CSV file. As it is, this is broken in the latest alpha. I may just try to hack away at your php to see if I can make it work.
Comment #3
TrevorG commentedUnfortunately I am not a skilled enough PHP coder to tackle this. Instead, since this is a new site, I reverted back to Drupal 6 and used a different importer - node-import - which correctly handles the tags.
Comment #4
yurtboy commentedsorry I just saw peoples posts.
My code looks for ||
my bad for not making that clear.
My client had commas in the tags so || was easier to deal with. It is the pipe or the character above the \ key.
Comment #5
TrevorG commentedyurtboy,
what do you mean it looks for ||?
When you go to import, the tags field per record looks like ";"tag1,tag2,tag3";" right?
Because thats how my csv looks but your replacement code did not make the tags explode into separate tags, it had the same effect as before where they were collectively imported as a single tag. I swear the next thing I will do is learn PHP so I can help fix these issues. I'm now getting pretty versed in MySQL so I can probably help in these import/export modules.
Comment #6
yurtboy commentedsorry ( -:
The path looks for the pipe pipe not a comma for the multi-tag import. The reason that pipe pipe is used is to prevent the issue of multi tags with commas not importing.
For example
"Tag, One, Tag Two, Tag Three"
Would import as
Tag
One
Tag Two
Tag Three
But really it should be
Tag, One
Tag Two
Tag Three
So when exporting your data use || to setup the field for the multiple tags.
If you let me know where you are getting your tags from, for example multi column spreadsheet, mysql etc I may be able to help.
Comment #7
wgsimon commentedThank you. That works perfectly. Why don't they include this by default?
Comment #8
mindgame commentedCan we not simply replace the line
by
?
The column in a csv file
...,"tag1, tag2 & 3",...
will result in two tags
- "tag1"
- "tag2 & 3"
You can even put , and " inside a tag.
Try the sample string from
http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ex...
To put it in a csv file simply convert it from
to
Works great for me.
Comment #9
micheleannj commentedpatch works for me in 6x-beta10 ... thanks!
Comment #10
ropaolle commentedTested mindgames fix and it worked great. I also used the same approche on file field.
Replace
$value = array($value);with
$value = is_string($value) ? drupal_explode_tags($value) : array($value);Comment #11
lyricnz commentedYes, a code-change in Feeds cause this (significant) regression, months ago.
#997392: Add support for tag-delimiters in taxonomy mapper
#925264: Don't allow commas in tag names
Comment #12
mukhsim commentedReformatted mindgames #8 patch with --no-prefix: http://drupal.org/node/1054616#comment-4152234
Comment #13
mukhsim commentedComment #14
emkamau commentedMukhsim #12 patch did not apply for me. Failed with:
___________
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
------------
Mindgames #8 patch working fine on7.x-2.0-alpha2
emk
Comment #15
mukhsim commentedHave you tried the patch from the module's folder and not from folder "mappers"?
mukhsim.
Comment #16
emkamau commentedI was trying it from the module folder.
emk
Comment #17
dynamicdan commented#12 for the win.
I just implemented it and it worked perfectly! (CSV with ; for token and , for tag separation).
Comment #18
bc24102 commentedyurtboy's patch worked for me. thanks.
Comment #20
johnvUsing Feeds Tamper, you can let "Tag1, Tag2, Tag3" process "Tag1", "Tag2", "Tag3" AND you have the option to set your own delimiter. It also already supports every mapper.
Comment #21
trevorbradley commentedThanks! The first patch worked for me!
Comment #22
worldlinemine commentedPost #20 indicates the same approach we use here to address this issue.
The module that was mentioned http://drupal.org/project/feeds_tamper and I recommend trying it out.
It may not be possible to assume that the default behavior of "," should always be to separate a list into multiple terms. Using something like feeds tamper helps to address that as an unknown.
Consider what happens if you have a real name like "Parsley, Sage, Rosemary and Thyme" and you don't want it broken into separate terms, et cetera. Just some thoughts regarding this topic.
Comment #23
dan1eln1el5en commented#12 works great, should be implemented into release code IMHO
Comment #24
johnbarclay commentedI feel the multi value functionality should be done with feeds tamper. The 7.x-2 version of this module is still pretty buggy but incredibly powerful. We should focus on getting existing bugs worked out at this point. I use the feeds tamper "explode" on comma feature for node references, taxonomy, and user references successfully.
Comment #25
tatianab commented#12 works for me
Comment #26
cubdesign commented#12 good job
Comment #27
ambientdrup commented#12 works for me. Is this patch going to be deployed to the latest stable version of the Feeds module? Should this just be included in the core stable module release?
-Trevor
Comment #28
sharif.tanveer commentedthat has worked for me in drupal 7x-2
Comment #29
zilverdistel commentedI like the approach with feeds_tamper. It's clean and intuitive. Only problem that's left for me is that I get a tag with an empty title if the field is empty for a feed item. I tried to get rid of that with the "trim" plugin from feeds_tamper, but that didn't work.
Comment #30
franzThis patch potentially breaks terms that have commas (I've worked with such terms already). Please, use Feeds Tamper as it provides the best specific solution for each case.
@zilverdistel, we have a major issue regarding empty fields, but maybe you can preg_replace the string to replace multiple commas with only one and trim to remove commas at end and start of the string before exploding it.
Comment #31
prakashrajavel commentedmindgame Thanks your given patch is working well.
Comment #32
j0rd commented#12 worked for me.
Comment #33
shaneonabike commentedCould we not role this into the deployed version?
Comment #34
deltahex commentedFeeds Tamper works well in this case but I have problem with duplicate terms created when using a shared between node types "term_reference" field. I tested creating a new Vocabulary and assign term reference field to the target node type. When I run the import everything goes fine, the new terms are created and there are no any duplicates but when this field is used in another content type as well then the import creates new tags/terms with the same name again and again...
i think it fails in feeds/mappers/taxonomy.inc line #141:
case FEEDS_TAXONOMY_SEARCH_TERM_NAME: ......
It just can't find that a term/tag with this name already exists... I was not able to find similar issue and I am posting this here. Maybe I should open a new issue and also try to fix this issue when I have time.
Please advice!
Comment #35
summit commentedHi, made new issue for this (#34): https://drupal.org/node/2119591
Greetings, Martijn
Comment #36
Max1 commentedhttp://drupal.stackexchange.com/questions/100190/feeds-importing-csv-int...