It would be great to be able to add parents when import terms (thereby creating hierarchical terms).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joshuajabbour’s picture

And here are two patches to do just that. Parent terms can be matched on term id, term name, feeds guid, or feeds url.

The patches contain the same fixes -- the first is against 6.x head, the second applies after #980212: Support guid/url for taxonomy term importer.

joshuajabbour’s picture

Status: Active » Needs review
David Goode’s picture

Status: Needs review » Needs work

Looks good, seems to work, but it'd be nice to support parental relationships between terms in the same import that isn't contingent on the order in which they appear in the CSV or RSS file. Might need some sort of memory to achieve this. Or, could just hack it and automatically import twice and update terms...that wouldn't be very nice though.

IE, for something like terms.csv:
"Term", "Parent"
a, b
b, --

This won't work.

joshuajabbour’s picture

Status: Needs work » Needs review

Yes, the parent terms must exist. While not perfect, I think that's pretty standard, as you can't reference something that doesn't exist.

Drupal behaves like this currently. Parent terms have to exist in order to be referenced (same with nodereferences). Not sure that imports should work differently.

IMO, what you're describing is an advanced behavior and could always be added later (however I believe it's fairly non-trivial). But the current patch does the actual mapping correctly.

beeradb’s picture

I think this is a good starting point for dependent terms. Importing terms (or anything) which requires dependent sets is non trivial. Every importer I've worked with has had the requirement on the developer to either correctly weight their import sets (in the case of something like migrate.module) or just structure their import files so the content which is depended upon comes before the dependent. I think this is a reasonable expectation to put on Developers, and is certainly an improvement over not having the ability to import parent terms.

David Goode’s picture

Status: Needs review » Reviewed & tested by the community

Good points, looks good in that context, although it might be nice to add some documentation or description of this behavior later for more novice users. Thanks.

philipz’s picture

Is someone trying to implement this for D7 version?
Ok I see this is hidden right now and after adding

'parent' => array(
        'name' => t('Term parent'),
        'description' => t('Parent of the taxonomy term.'),
       ),

to getMappingTargets function I importet child terms. They got messed up because ids are not the same but it's a step forward.

rickmanelius’s picture

I agree with beeradb and David Goode, it should be the responsibility of the data being imported to ensure the parent data already exists. Otherwise feeds would have to do some preprocessing to properly order the file (awesome, but I'm not sure anyone is gung ho to put that in right now).

What is the status of this patch? I see reviewed and tested by the community, but I didn't see the patch code in the latest dev for 6.x.

I'm asking because I'm very interested in this functionality for the same functionality in Drupal 7 (see current feature request ticket #1159628: How do you import a hierarchical taxonomy with feeds? for feeds-7.x-2.0-dev. My goal being importing 1 level of parent child nodes.

rickmanelius’s picture

This patch here also works, and adds in the ability to set the taxonomy weight as well.
#1152940: Feeds term import with hierarchy and weight.

I tested it and it works. I wonder which of these is the better solution?

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs work

This also needs tests, and to be patched for 7.x first.

rickmanelius’s picture

@Dave Reid,
#1152940: Feeds term import with hierarchy and weight is against 7.x and these patches appear to duplicate functionality. Should we simply close this one and use the other?

janusman’s picture

Maybe this is unrelated, but, is content_taxonomy mapping from the parent feed node working (on D6 branch?)

divined’s picture

How to save deepest term from all hierarchy?

I have the following structure:

Parent1
--Child1 //here a problem
--Child2
--Child3
Parent2
--Child1 //here a problem
--Child4
--Child5

David_Rothstein’s picture

This sounds somewhat related to the following issue in the Feeds Tamper module: #1319278: Support automatic importing of the term hierarchy for nested taxonomy terms

morten_kroyer’s picture

Patch from #1 ported to work against current stage dev.

Also work with 6.x-1.0-beta13 release.

twistor’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, feeds-term-parent-1004668-15.patch, failed testing.

twistor’s picture

Status: Needs work » Closed (outdated)