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?

Comments

ropaolle’s picture

Subscribe

TrevorG’s picture

Unfortunately, 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.

TrevorG’s picture

Unfortunately 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.

yurtboy’s picture

sorry 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.

TrevorG’s picture

yurtboy,

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.

yurtboy’s picture

sorry ( -:
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.

wgsimon’s picture

Thank you. That works perfectly. Why don't they include this by default?

mindgame’s picture

Can we not simply replace the line

$terms = array($terms);

by

$terms = is_string($terms) ? drupal_explode_tags($terms) : array($terms);

?

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

this, "somecompany, llc", "and ""this"" w,o.rks", foo bar

to

this, ""somecompany, llc"", ""and """"this"""" w,o.rks"", foo bar

Works great for me.

micheleannj’s picture

patch works for me in 6x-beta10 ... thanks!

ropaolle’s picture

Tested 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);

lyricnz’s picture

Yes, 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

mukhsim’s picture

StatusFileSize
new440 bytes

Reformatted mindgames #8 patch with --no-prefix: http://drupal.org/node/1054616#comment-4152234

mukhsim’s picture

emkamau’s picture

Version: 7.x-2.0-alpha3 » 7.x-2.0-alpha2

Mukhsim #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

mukhsim’s picture

Have you tried the patch from the module's folder and not from folder "mappers"?

mukhsim.

emkamau’s picture

I was trying it from the module folder.

emk

dynamicdan’s picture

#12 for the win.

I just implemented it and it worked perfectly! (CSV with ; for token and , for tag separation).

bc24102’s picture

yurtboy's patch worked for me. thanks.

Status: Needs review » Needs work

The last submitted patch, multi-tag-import-1039134-4235274.patch, failed testing.

johnv’s picture

Using 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.

trevorbradley’s picture

Thanks! The first patch worked for me!

worldlinemine’s picture

Post #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.

dan1eln1el5en’s picture

#12 works great, should be implemented into release code IMHO

johnbarclay’s picture

I 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.

tatianab’s picture

#12 works for me

cubdesign’s picture

#12 good job

ambientdrup’s picture

#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

sharif.tanveer’s picture

Component: Code » Feeds Import
Assigned: yurtboy » Unassigned
Status: Needs work » Reviewed & tested by the community

that has worked for me in drupal 7x-2

zilverdistel’s picture

I 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.

franz’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

This 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.

prakashrajavel’s picture

mindgame Thanks your given patch is working well.

j0rd’s picture

#12 worked for me.

shaneonabike’s picture

Could we not role this into the deployed version?

deltahex’s picture

Feeds 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!

summit’s picture

Component: Feeds Import » Code

Hi, made new issue for this (#34): https://drupal.org/node/2119591
Greetings, Martijn