I have a content type called Items.
Within the items I have 3 unlimited term reference fields.
Location (field_location_pi)
Phase (field_phases_pi)
Structure (field_structure_type_pi)
I am creating a drill down system using reference option limit.
So in a second content type, you would select item, then the location taxonomy field would be limited by those designated by that item, then the phases would be limited by those in the locations and the structure by those in the phases.
For this to work I need to have a reference field in each taxonomy that refers to taxonomy that limits it.
For Example
An Item is called Pour Cement. This item has 3 possible locations terms tagged: North, South, West. It also has 2 Phases terms tagged: First, Second. Finally it also has two structures terms tagged: sidewalk, wall.
So the Location Taxonomy Terms have an entity reference field (field_pay_items_loc) that references all Items tagged with the terms.
Then the Phase Taxonomy Terms have a term reference field (field_location_ref) that references all the Locations they have in common in the Items.
Then the Structure Taxonomy Terms have a term reference field that references all the phases they have in common in the items.
To further extrapolate on the aforementioned example:
Each Location Term: North & South & West have one item referenced: Pour Cement
Each Phase Term: First & Second have 3 locations referenced: North, South, West
Each Structure Term: Wall & Sidewalk have 2 Phases referenced: First, Second
Right now I have to set this manually, but I would like to create a rule that automatically selects the correct item(s) in correct reference fields when a pay item is saved or created.
I can do this when the reference fields are limited to 1 by using the following rule, This rule adds the item to the phase and the phase to the location. I know I need to change the action to adding to a list and it needs to happen within a loop but, for the life of me, I can not get it working when the reference fields are set to unlimited.
I've been slogging my way through the components (I watched this video: https://youtu.be/Bol6kNwVenA on creating multiple back links for a guide) and I can not get it to work with taxonomies. Any advice would be greatly appreciated.
{ "rules_add_pi_to_phase" : {
"LABEL" : "Add item to Phase",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : {
"node_update--item" : { "bundle" : "item" },
"node_insert--item" : { "bundle" : "item" }
},
"IF" : [
{ "entity_has_field" : { "entity" : [ "node:field-phases-pi" ], "field" : "field_pay_items_loc" } }
],
"DO" : [
{ "data_set" : {
"data" : [ "node:field-phases-pi:field-items-loc" ],
"value" : [ "node" ]
}
},
{ "data_set" : {
"data" : [ "node:field-phases-pi:field-location-ref" ],
"value" : [ "node:field-location-pi" ]
}
}
]
}
}
Here is the rule I have so far to loop through all the phases in the Item. Without the component.
{ "rules_add_pi_to_phase" : {
"LABEL" : "Add PI to Phase",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : {
"node_update--pay_item" : { "bundle" : "pay_item" },
"node_insert--pay_item" : { "bundle" : "pay_item" }
},
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "pay_item" : "pay_item" } }
}
}
],
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "node:field-phases-pi" ] },
"ITEM" : { "phase_item" : "Current Phase" },
"DO" : []
}
}
]
}
}
I just realized that I wasn't thinking about this the right way. I need to get all the phases terms referenced (field_phases_pi) in the item AND all the structure types terms referenced (field_structure_type_pi) in the item too. Then I need to add all the phases terms to the referenced field (field_phases_ref) to all the structure types terms referenced. So that would be multiple loops, I guess.
Here is my attempt at the component but I know it's not right because when I try to add it to the rule it doesn't allow me to pick a data selection and it wants Taxonomy term identifiers that I don't know what to do with...
{ "rules_add_phase_to_structure_type" : {
"LABEL" : "Add Phase To Structure Type",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
"phase_term" : { "label" : "Phase To Add", "type" : "list\u003Ctaxonomy_term\u003E" },
"structure_term" : {
"label" : "Structure Type To Add To",
"type" : "list\u003Ctaxonomy_term\u003E"
}
},
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "structure-term" ] },
"ITEM" : { "structure_item" : "Current Structure item" },
"DO" : [
{ "entity_fetch" : {
"USING" : { "type" : "taxonomy_term", "id" : [ "structure-item:tid" ] },
"PROVIDE" : { "entity_fetched" : { "fetched_structure" : "Fetched structure" } }
}
},
{ "list_add" : {
"list" : [ "phase-term" ],
"item" : [ "structure-item" ],
"unique" : "1"
}
}
]
}
}
]
}
}