Over the last few days I've been investigating and experimenting on how to use rules to alter fields within a paragraphs bundle on a node. The paragraph field on the node allows for multiple values(to a maximum of 6). In the paragraph bundle there is a radio button field where users select a "type" which then triggers the visibility of a corresponding field. The 'Conditional Fields' module has an option to 'reset to default value' when a dependency is not triggered, but this fails to work for me(needs a patch I believe). In place of that I am using rules to clean the form on submit. This worked perfectly with normal node fields, however it's not so simple when the fields I need to clean are inside a paragraph entity and there are multiple instances of the entity within the field.
In my experimentation I was able to reset the first and only the first paragraph bundle isntance with a data selector that looks like this:
node:field-paragraphs-categories:0:field-select-service
The problem here(I think) is that I'm selecting only the first 'row' in the paragraphs field thanks to the :0: in the data selector? I'm only guessing at the meaning of that number, the labeling of data selectors is cryptic to me.
Without that 0 or any of the other numbers(ex: 1,2,3) shown in the data selector options I can't even access the appropriate field I want to alter.
Screenshot of available data selectors
I figured that the right direction is to loop through the paragraphs field and select each 'row' individually and then, through the current list item of the loop, select the appropriate field to alter it that way but so far have been completely unsuccessful.
I believe I need a component(of type rule) and a standard rule to do this, right?
The rule:
Condition = Entity has field - Parameter: Entity: [node], Field: field_paragraphs_categories
Loop = node:field-paragraphs-categories & add component as an action
Action = Fetch entity by id - current-paragraph:item-id
The component(type rule):
Condition = Data comparison - current-paragraph:item-id(from loop):field-service-type
Action = Set a data value - current-paragraph:item-id(from loop):field-select-service
I can't seem to simply pass the id of the current item of the loop to the data comparison or action in the component so i can drill down to the fields it contains. This is where I'm getting stumped. Perhaps my entire method is wrong though, I don't know.
The closest instruction I've been able to find is in this thread https://www.drupal.org/node/1699712 @ #9 but, while similar, offers no insight into the parts I'm having difficulty with.
The short version of this support request is:
How do I loop through a paragraphs field with multiple values, set a data comparison condition on 'service-type', and then set a data value for 'select-service' if the condition evaluates to true.
CLARIFICATION:
In trying to add any data comparisons or actions such as "set a data value" I am unable to find a way to iterate over each row and then alter a field in that row like so:
First iteration = node:field-paragraphs-categories:0:field-select-service -> set value
Second iteration = node:field-paragraphs-categories:1:field-select-service -> set value
Third iteration = node:field-paragraphs-categories:2:field-select-service -> set value
fourth iteration = node:field-paragraphs-categories:3:field-select-service -> set value
And so on.
As far as I understand right now, without automatically looping through that index number I cannot set data values for fields inside "paragraphs-categories" unless I manually make a rule(or action within a rule) for each possible index number(0,1,2,3,4,5,etc).
Final Findings
After some further testing it appears that the issue is that paragraphs does not make the current list item fields available for manipulation within the loop(you can, however, access them for creating messages and maybe other actions). The field collection module DOES expose field collection fields in a rules loop and the refinements outlined by Pierre.Vriens work perfectly with that module instead.