Problem/Motivation
I want to use conditional fields in a form where the structure form array does not match the structure of the form_state values array. Drupal supports this by providing two sets of parents, the '#array_parents' for the $form and the '#parents' for $form_state['values']. In conditional_fields_attach_dependency the parents for a conditional field element are set equal to '#parents' and this is then used to get the widget element in the $form array. This is not correct.
Solution
Replace '#parents' with '#array_parents'.
This change will make Conditional Fields much more versatile when it comes to be a general API.
Questions
I'm not sure what to do about field parents.
Comment | File | Size | Author |
---|---|---|---|
#4 | 2298953-4.patch | 811 bytes | rlmumford |
#1 | 2298953-1.patch | 1.56 KB | rlmumford |
Comments
Comment #1
rlmumfordhere's a patch.
Comment #2
rlmumfordComment #4
rlmumfordComment #5
rlmumfordComment #6
rlmumfordThere's another contrib module that now requires this patch #2124191: Introduce Conditional Fields support
Comment #7
andrewbelcher CreditAttribution: andrewbelcher commentedI can confirm that the patch in #4 solves this problem.
Comment #8
rlmumfordCan this be committed please? It's been 9 months!
Comment #10
peterpoe CreditAttribution: peterpoe as a volunteer commentedComment #12
mbayntonThis patch looks dangerous. Here's a snippet with the patch applied:
Note that it is guarded by an
isset($dependee['#parents'])
, which is the thing that used to be read within the if block. Now, we read$dependee['#array_parents']
, which could be undefined if the function is called with no $id and a field name string in $dependee.I suspect a good solution would be to just assume #array_parents should equal #parents for the string-as-$dependee case. I'd be happy to do a patch on this issue or a separate one if requested.