Easy enough, no? ... All you need to know is how to actually perform a check in Rules to verify "If that term is already contained in the list of terms of your taxonomy". That's what you can do with "List contains item", with list
= the terms that exist before the rule starts executing, and item
the term [node:field-a][node:field-b]
.
Part 2 - Partial solution
Below is a partial solution for what is above (it does need some extra "work" ...
Updated Rule
Part 2 - Solution using Conditional Rules
HaveBelow is a look at this rule (which now performs an appropriatepossible solution using Conditional Rules Component). The improved rule looks like so:
{ "rules_improved_combination_of_taxonomy_terms""rules_combine_taxonomy_terms_without_creating_duplicates" : {
"LABEL" : "Improved"Combine combinationtaxonomy ofterms taxonomywithout terms"creating duplicates",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_conditional" ],
"ON" : { "node_view--article" : { "bundle" : "article" } },
"DO" : [
{ "drupal_message" : { "message" : "Value of term for field C shouldwill be set to: \u003Cstrong\u003E[node:field-a][node:field-b]\u003C\/strong\u003E"strong\u003E." } },
{ "variable_add" : {
"USING" : { "type" : "text", "value" : "[node:field-a][node:field-b]" },
"PROVIDE" : { "variable_added" : { "variable_added""combined_term" : "Added"Combined variable"Term" } }
}
},
{ "entity_query" : {
"USING" : {
"type" : "taxonomy_term",
"property" : "vocabulary",
"value" : [ "node:field-a:vocabulary" ]
},
"PROVIDE" : { "entity_fetched" : { "existing_terms" : "Existing Terms" } }
}
},
{ "component_rules_add_term_if_not_yet_created""variable_add" : {
"term_parm""USING" : { "type" : "boolean", "value" : "0" },
"PROVIDE" : { "variable_added" : { "new_term_exist" : "New term exists" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "existing-terms" ] },
"ITEM" : { "current_term" : "Current term" },
"DO" : [
{ "CONDITIONAL" : [
{
"IF" : { "text_matches" : { "text" : [ "current-term:name" ], "match" : "[combined-term:value]" } },
"DO" : [
{ "data_set" : { "data" : [ "new-term-exist" ], "value" : "1" } },
{ "data_set" : { "data" : [ "node:field-c" ], "value" : [ "current-term" ] } },
"terms_list_parm" { "drupal_message" : [{ "existing"message" : "Term \u003Cstrong\u003E[node:field-terms"a][node:field-b]\u003C\/strong\u003E already exists (no need to create it now)." } }
]
}
]
}
]
}
},
{ "CONDITIONAL" : [
{
"IF" : { "data_is" : { "data" : [ "new-term-exist" ], "value" : "0" } },
"DO" : [
{ "entity_create" : {
"USING" : {
"type" : "taxonomy_term",
"param_name" : "[variable"[combined-addedterm:value]",
"param_vocabulary" : "tags"
},
"PROVIDE" : { "entity_created" : { "entity_created""term_created" : "Created entity"term" } }
}
},
{ "entity_save" : { "data" : [ "entity"term-created" ], "immediate" : "1" } },
{ "data_set" : { "data" : [ "node:field-c" ], "value" : [ "entity"term-created" ] } },
{ "drupal_message" : { "message" : "Term \u003Cstrong\u003E[node:field-a][node:field-b]\u003C\/strong\u003E did not yet exist and was created just now." } }
]
}
]
},
{ "entity_save" : { "data" : [ "node:field-c" ], "immediate" : "1" } },
{ "drupal_message" : { "message" : "\u003Cstrong\u003ENote\u003C\/strong\u003E: After updating field A or B, a page refresh is needed to actually SEE a value of field C = \u003Cstrong\u003E[node:field-a][node:field-b]\u003C\/strong\u003E." } }
]
}
}
New Rules Component
Even though it's not an obvious rule to digest (I think), it mostly does 2 things:
This is the related Rules Component:
- Set the value for field C to an existing term (if it already exist).
- Create the term for field C on the fly (if it does not yet exist) and then use that to set the value for field C
{ "rules_add_term_if_not_yet_created" : {
"LABEL" : "Add term if not yet created",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
"term_parm" : { "label" : "Term Parameter", "type" : "taxonomy_term" },
"terms_list_parm" : {
"label" : "List of Terms Parameter",
"type" : "list\u003Ctaxonomy_term\u003E"
}
},
"IF" : [
{ "list_contains" : { "list" : [ "terms-list-parm" ], "item" : [ "term-parm" ] } }
],
"DO" : [
{ "drupal_message" : { "message" : "Term with name [term-parm:name] does exist already.\r\nTodos: (1) move Rules Actions \u0022Create Entity\u0022 and \u0022Save Entity\u0022 to Actions of this component and (2) Get the negation of the Rules Condition here to work if value of Field C is still empty " } }
]
}
}
However, there is 1 minor detail to be aware of, as detailed in the message of the very last Rules Action ... For anybody interested in addressing that (to make that message obsolete), please post an extra answer and feel free to use this rule here to start from.
AllNote: even though, in theory, you should also be able to use Rules Components instead of Conditional Rules, the key challenge with that remains now is that you run in a tough-to-debug issue when passing values to implement the 2 todos as shownsuch Rules Components, in the "Message" atcases where the endvalue of Field C is still blank (eg when creating a new node).
PS: Q: How do you eat an elephant? A: 1 bite at a time ... (though there is only1 bite left of it now ... I think).