0

For a project i would like to achieve the following:

Using 2 fields in a content type field_parent = reference to term This field references to vocabulary 'parent terms'

I have a second field called 'field_child'. This field has to be a child term of the 'field_parent' term

sample: field_parent --> apples field_child --> green

in taxonomy I see Apples - green Pears - green

How can I achieve this? Is there any module available or snippet.

  • Max be the conditional fields module is helpfull for you: drupal.org/node/1349882#comment-6190164 – BetaRide Jul 10 '12 at 12:16
  • Have you already build out your vocabulary as a hierarchical (parent-child) vocabulary or are they separate? If they're separate, is anything keeping you from just having these be two separate term reference fields? – Boriana Ditcheva Jul 11 '12 at 13:30
  • @betaride you sent me to the rules page.. not sure what to do there. – pindaman Jul 11 '12 at 14:10
  • @boriana my taxonomy is built by tag field (term reference field) in the node form. i have 2 term field referencing to the same vocabulary. I had testedthe following code: blog.yawd.eu/2011/… that works for single node creations. But when using it with my feed mapping is get an error. "Missing bundle property on entity of type taxonomy_term." I just cant get to create parent->child term relations on the fly with my imported feeds. If anyone has something lying around maybe for a small donation i'd be delighted. – pindaman Jul 11 '12 at 14:10
  • Taxonomy Term Reference Tree widget allows you to select either the lowest level in a hierarchy or to select its parents as well automatically. – beth Jul 11 '12 at 15:07
0

If your problem is with doing this via feeds (from your comment to me), I'd try the following:

It looks like you're already using the feeds module and that your incoming terms are mapped to your term reference. Good! It also sounds like you have a hierarchical vocabulary. Good.

Now, I'd just have one single term reference field on your node. No need to have one for the first level and one for the second level of your vocab. Just have ONE term reference field, and set that single term reference field to take an unlimited (or whatever number greater than 1) number of values in the 'Manage fields' page of your content type. (It won't just take one for the parent and one for the child, but both can be set once).

Download and install the Feeds Tamper module, which allows you to process results in various ways during the feeds import. Once your feeds tamper module is installed, when you go to /admin/structure/feeds, you should see a 'Tamper' link where you can configure your tamper settings.

For this to work properly, I'm assuming you can make your import file be in the form of 'Apples;Green' for the hierarchical terms -- i.e. that you can provide them in one column, separated by a special character, and that that column is mapped to your one single term reference field. If you can do that, then you can set your tamper to parse them out and set both the parent and child of the vocabulary this way.

Go to the 'Tamper' link, find the field that represents this taxonomy and select 'Add plugin'. Then select the 'Explode' plugin and specify the special character that will separate your parent/child terms.

Test with an import, and let me know if that gets it working properly....

  • 1. I have a "node processor" feed. 2. created csv for testing with "Subcategorie" "Wonen;Badjas" ="parent;child" 3: setup feeds tamper Explode with String separator ";" 4: import cvs from site/import (file upload) 5: nodes are created, 6: Terms 'Wonen' and 'Badjas' are created without parent-child relations – pindaman Jul 12 '12 at 12:50
  • Oh, I see what you're saying. But aren't these terms already parent-child when you created them? I think I misunderstood. I thought you already had the vocabulary built up, but it sounds like you're creating terms on the fly... that's a bit different. – Boriana Ditcheva Jul 12 '12 at 13:01
  • Otherwise, you know that you can have hierarchical (parent-child) vocabulary terms if you create them yourself beforehand, right? You can do that by filling in the 'Relationship' portion on the term creation page... – Boriana Ditcheva Jul 12 '12 at 13:08
  • I just thought of the misunderstanding you talked about. My taxonomy/vocabulary is empty on node creation. my field_category creates the parent term and my field_subcategory creates a child term. So no terms are in the vocabulary before node creation/feed import. I know i can created the term on forehand, but that is way too much work. All needs to be created on the fly. Thats why i tried the module in my earlier response. BUt that creates errors – pindaman Jul 12 '12 at 13:40
  • Still no solution for this.... – pindaman Jul 15 '12 at 8:30
0

I used the Hierarchical taxonomy module. Now I can import feeds with parent /child taxonomy using it AND the Feeds Tamper module. It works perfect; you only need one import run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.