This is a very odd scenario, so bear with me:

I'm importing data from a CSV file via the Feeds module to create product reference nodes. There are 3 columns that contain a term (let's call the columns "Code Types"), so naturally, I set up 3 vocabularies for the product reference nodes to use and mapped/imported the Code Type's terms into each. The client had determined long ago that the terms would not make much sense to the customers, so being able to search for products by selecting a combination of terms would not be helpful. To combat this, new user-friendly keywords were added on the client's old site by assigning each a combination of the 3 terms. I'm trying to replicate this for the new site, and it's driving me insane.

I first began by adding the same 3 Code Type vocabularies to a new 4th "Product Keywords" vocabulary (Yes, terms within terms). After no luck with term or entity reference fiddling, EVA, etc., I decided referencing would go smoother if I made the Keywords a content type with the 3 Code Type term reference fields instead of its own vocabulary. I'm still open to either option, though.

What has to happen is that a product reference node is automatically assigned the Keyword term that exactly matches its 3 Code Type term reference fields, and not all Code Type term reference fields have to have a value. Here are some examples:

Product #42 has: CodeType1 = "Red" CodeType2 = "Wheel" CodeType3 = "Hot Dog"

Product #216 has: CodeType1 = [empty] CodeType2 = [empty] CodeType3 = "Hot Dog"

Keyword "Sloth" has: CodeType1 = "Red" CodeType2 = "Wheel" CodeType3 = "Hot Dog"

Keyword "Muffin" has: CodeType1 = [empty] CodeType2 = [empty] CodeType3 = "Hot Dog"

Product #42 needs to have the keyword "Sloth" automatically assigned to it.

Product #216 needs to have the keyword "Muffin" automatically assigned to it.

Sorry for the longwindedness. It's urgent, and I'm edging toward panic mode. Any ideas? Please?

2 Answers 2


These are some ideas to accomplish this through Drupal (rather than Excel).

You could do this with a combination of custom modules and Rules, or solely with Rules (which might be a bit more laborious). I'm focusing on the version only with Rules. I haven't tested this, so there may be some adjustments needed.

1. Create a "Catalog" content type that catalogs all combinations of codetypes

Create a content type that will act as a "catalog of codetypes", containing all possible combinations of codetypes and their unique keyword assigned to each combination. This would take an initial investment of time for someone to enter all combinations. Be sure to enter a special code (like the string "empty") when a codetype is not present in a specific combination.

2. Create a View of the "Catalog" content type with three Contextual Filters that filter for a specific combination of the 3 codetypes

(This step needs to be tested and possible tweaked quite a bit). You would need to define the path as /catalog/%/%/% to create placeholders for empty codetypes. There would be 3 Contextual Filters for each of the 3 codetype fields in the catalog. Be sure to provide the fixed default value "empty" in the configuration of When the filter value is not in the URL. The result of this View would be a single record that contains the specific combination of codetypes.

3. Install View Bulk Operations and add it to the View

After enabling it, add a VBO field to the View created in step 2. There is no need to select a specific operation. This field will be used to load the single catalog record into Rules later on.

4. Create a Rule that reacts to new (imported) Product nodes being saved

This Rule will react to the Products being created through the use of Feeds. Basically it needs to load a list of entity objects from the VBO you created above. Pass the three codetypes as arguments the the View.

5. Use the Rule to Set data value of the Keyword field in each of the imported Products.

This step may require some tweaking. You will need to bring into scope the Keyword field of the Catalog record provided by the View. That may involve creating a separate Component that has a condition that brings it to scope, or installing Conditional Rules to create an if statement that brings it to scope. Once the Keyword field of the Catalog node is brought into scope, you use its value to assign it to the Keyword field of the imported Product

So, that's it in a nutshell. You could replace several of the steps with code in a custom module, and avoid using VBO and Rules altogether - you would use EntityFieldQuery to load the Catalog node with the three codetypes, and hook_node_insert() to react to the Product node being imported/created. There may be alternative hooks in the Feeds API that may make this possible too.

I hope this helps... Let me know if you have questions.


OK, this is what I would do (hoping that I'm understanding the question!). I assume the keywords need to be hard-coded to the product, and not assigned dynamically. Is that right? If so:

I would not bother doing these combinations with Drupal. I would do the combinations with Excel, then import the resulting CSV sheet with Feeds to Drupal.

For example, in the same excel sheet I would have:

  1. An area that defines the keywords in rows, each with 5 columns: 1. Codetype1, 2. Codetype2, 3. Codetype3, 4. a string concatenation of the 3 codes, and 5. the keyword itself, and then

  2. An area with the a row for each product with at least 4 columns each, containing the 3 codetypes, and a concatenation of the 3. Then a formula column for each row that uses =vlookup() to look up the concatenation in the Keyword area, and to insert the appropriate Keyword

See image for clarification. The formula I used is in the Keyword column in the Product area: =VLOOKUP(E3,$K$3:$L$5, 2,0) in cell [F3] for example.

enter image description here

Once keywords are calculated this way you can copy and paste the Keyword column into a new CVS and import with Feeds. Good luck!

  • Yes, that would indeed be the sensible way, but unfortunately, that is not the client's way :) I have to import these CSV files AS-IS, which is insane, I know. The data is coming from a system that is 20+ years old. And since they want to re-import their inventory weekly, they're not going to want to involve any middle-man CSV file fiddling, blah blah blah The good news is that I may have found a solution: I went with the option to have the Keywords as a taxonomy (which had the 3 term reference fields inside of it). I'm trying the Reference Field Option Limit module, and it's looking good :)
    – McTwist
    Dec 31, 2015 at 2:47
  • The closest I've gotten to solving this issue is with the use of the Reference Option Limit module. I can get the correct keyword to appear in the dropdown (there will always be only one to select, so to make sure it appears as the "default" value, I set the field to required). Alas, it doesn't appear that the value is actually stored - it doesn't show up when viewing the node or used in a view. I have tried countless ways to programmatically re-save the nodes - VBO "Save Content" and node_save($entity); PHP code, the Resave Nodes module, re-running the feed import - nothing. Any ideas?
    – McTwist
    Jan 1, 2016 at 8:25
  • Not sure if you still need ideas about this. I'm not sure I completely understand the issue. This is what I understand: you are importing nodes with feeds. Each node contains three "code types." Each combination of code types should generate a unique keyword for the node, which should be automatically added to each imported node. Is this correct? I have a few ideas that may be useful. Let me know if you still want to hear them
    – argiepiano
    Jan 1, 2016 at 21:41
  • Yes, that is correct! And please send me your ideas!
    – McTwist
    Jan 2, 2016 at 6:49
  • See my second answer
    – argiepiano
    Jan 2, 2016 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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