Attached is a patch I'm using to import nodes that have hierarchical taxonomy terms. I know that there was some work done with a patch and the use of "feeds-tamper" but it seemed more prudent to have this self contained within the feeds taxonomy mapper itself.

Notes on term parsing:

  • I chose "|" as the term separator. This probably deserves some discussion and maybe even a config option.
  • Empty terms even between separators are ignored. So "Root|branch 1|||branch2" is the same as "Root|branch1|branch2".
  • All terms are trimmed. So "Root | branch1 | branch2" is the same as "Root|branch1|branch2"
  • All terms are created with proper respect for each other if they don't exist. So if importing "Root|branch1|branch2" where only "Root" is present it will create "branch1" as a child of "Root" and "branch2" as a child of "branch1" assigning "branch2" to the node.
  • It still suffers from the numeric term problem in that the default handling of numerics as TIDs is still intact. However if the "|" separator is present than PHP won't see it as numeric. So "123|", "|123" and "Root|123" will all look for terms with those values instead of TIDs.
  • All simple string terms without a "|" in them will be treated as a root (no parent) term. So if you had a "cats" term with a child of "black" and you import "black" then it will create a new term called "black" at the root (no parent). This alters the usual behavior.
  • There is no attempt at term cleanup in case of failure. So if something breaks after the term was processed and the node doesn't import its probable that the terms will still remain.
CommentFileSizeAuthor
feeds-tax_hier-7.x-2.0-a4.patch1.8 KBjafcobend

Comments

prodigeek’s picture

I'm not able to get this work. Only the child term is being imported, not the parent. I ideally want both the parent and child terms to be included on the node fields.

Thank you for the patch.

twistor’s picture

Priority: Major » Normal

Let me just start by saying that feature requests are almost always marked as normal.

Please don't let me discourage you, but there's a reason this was brought up in Feeds Tamper. It is very use-case specific.
There are several issues:

  • I'm not entirely sure what this does.
  • I'm guessing that it provides new functionality to existing mappers. Is it backwards compatible?
  • As mentioned, hardcoding | as the separator.
  • What if existing users have |'s in their terms?

Please link to the other issues mentioned.

megachriz’s picture

Component: Feeds Import » Code

Sandbox module for Feeds hierarchical taxonomy:
https://drupal.org/node/1540722