Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Ideally Feeds' handling of taxonomy term fields would include options to import only incoming data that matches existing terms, rather than free tagging which is what it effectively does now. Meanwhile, a Tamper plugin can filter the input down to only data that match existing terms.
For example, if the imported field data were "My Tag, My Other Tag, My Random Made-Up Tag" and the chosen vocabulary only contained terms named "My Tag" and "My Other Tag," then this tamper plugin would filter the input to "My Tag, My Other Tag."
Comments
Comment #1
biwashingtonial CreditAttribution: biwashingtonial commentedHere's a first draft. Works in preliminary testing. I wrote it in a hurry, so we can play Where's Waldo with the dumb glitch I might have left in it.
Comment #2
Bastlynn CreditAttribution: Bastlynn commentedFound a bug with this - having to do with your use of static. +1 for caching, -1 for... caching.
If you have multiple maps going from the same field to different taxonomies, you'll end up mapping all of them against the first one declared.
Comment #3
Bastlynn CreditAttribution: Bastlynn commentedPerhaps this instead?
Comment #4
biwashingtonial CreditAttribution: biwashingtonial commentedYou found Waldo! Thanks. :)
Re-rolling.
Comment #5
David_Rothstein CreditAttribution: David_Rothstein commentedI needed this feature, and the above patch seemed to work well in my limited testing. Moving to "needs review".
The code should probably use drupal_static() rather than static, but that's relatively minor...
Comment #6
twistor CreditAttribution: twistor commentedLooking good. There are some minor whitespace issues. It will need tests though, and that will be a bit harder than the normal tests.
Comment #7
ChristopheDG CreditAttribution: ChristopheDG commentedWould your solution fix the following issue too:
I import a feeds line with a category field "saddles/parts".
I have an existing vocabulary with hierarchical terms:
machinery - parts
saddles - parts
After import and exploding the category field into taxonomy, I find all the saddle parts nodes mapped to the machinery parts.
Apparently the hierarchical term structure isn't taken into account. "Parts" under "Saddles" should first be looked for.
Comment #8
David_Rothstein CreditAttribution: David_Rothstein commentedI ran into an issue with the above patch. It has an inconsistency in that for single-valued fields, it replaces non-existent terms with an empty string, but for multi-valued fields, it filters them completely out of the array (rather than replacing them). This can cause problems with multivalued fields being mapped to the wrong place (in particular I ran into this when importing fields contained within a field collection; fields that were supposed to be attached to one field collection item were getting imported into a different one, due to the missing array items).
The attached reroll fixes that by consistently using 0's to represent missing terms in both cases.
Still "needs work", because per #6 there are no tests.
Comment #9
bibo CreditAttribution: bibo commentedI tested the patch and it works flawlessly. I would say this plugin is rather commonly needed, and I hope it gets to the module soon. If someone creates tests..
@ChristopheDG: I'd say thats a separate issue. You should probably not have several terms with the same name in the vocabulary (and/or only one parent per term).
Comment #10
acidpotato CreditAttribution: acidpotato commentedThis is a great plugin and exactly what I was looking for, so thank you so much for the work so far. One interesting addition to this plugin would be able to identify variations in spellings or presentation in the source and capture that in the target value.
Currently I am importing data from a couple of wine stores from their websites. I am importing to the term field from the "wine title field". To give an example, Same wine could be named in different way on different stores - 2009 Stags Leap Cab Sauv Russian River or 2009 Stags Leap Cab Sauv Russian River Valley. So to summarize -
Entity - Wine
Vocabulary - Wine Region
- Term - California
Sources - 2009 Stags Leap Cab Sauv Russian River Valley and 2009 Stags Leap Cab Sauv Russian River
Is it possible to create an input box to allow the source data to have variations that will map to the same terms in the target field? So users can enter in the input box -
Russian River Valley|California
Russian River|California
And both of these values will be mapped to California. This of course would be in addition to source data "California" being mapped to target term California.
This feature will allow for additional flexibility for users and wider usage of this plugin, especially when one doesn't have control over source data. I'll buy a drink for anyone who comes up with a solution!
Comment #11
acidpotato CreditAttribution: acidpotato commentedAhh.. what I described above can be achieved by using plugin in #1623560: find replace by List or #1525540: Find & Replace multiple and then using the existing taxonomy term plugin. Has worked very well for me so far, so thanks again!
Comment #12
tyler-durden CreditAttribution: tyler-durden commentedI can also confirm the patch in #8 works beautifully. This was my major issue with feeds, and it's solved. THANKS!!
Comment #13
mErilainen CreditAttribution: mErilainen commentedWorks for me also
Comment #14
7wonders CreditAttribution: 7wonders commentedNumber 8 works great. If you use the synonyms module you can use the below for an "existing term OR synonym" version of the same.
Comment #15
twistor CreditAttribution: twistor commentedIs this still needed after #1019688: Taxonomy mapper options: term name +tid, term name, tid, guid (avoids mapping error for Numeric taxonomy term, too)?