I have gotten myself into a bit of a bind here [conceptual pun intended]. Rather than pasting a ton of code, I’d like to pose this as a sort of theoretical question.
The case is that I want to make a front end for users to be able to configure event handlers where the events are, well, fine-grained with conditional logic. So a configuration setting might look something like,
some_event.condition1.condition2.condition3.do_something = true|false
I took it into my head to make a hierarchical data structure out of this, e.g.,
$config = [ 'event_foo' => [ 'condition_a' => [ 'condition_p' => [ 'do_action_x' => $boolean, 'do_action_y' => $boolean, ], 'condition_q' => [ 'do_action_x' => $boolean, 'do_action_y' => $boolean, ] ], 'condition_b' => [ 'condition_p' => [ 'do_action_x' => $boolean, 'do_action_y' => $boolean, ], 'condition_q' => [ 'do_action_x' => $boolean, 'do_action_y' => $boolean, ] ], ] /** etc */ ];
and now the general issue I am having with this wildly complicated scheme is that it’s… wildly complicated. But seriously, folks – I made a JSON object out this for persistence, read it back from disk and
json_decode() it, and then tried using the data to populate a Zend\Form\Form containing about 27 checkboxes named using array notation, e.g.,
Creating these elements requires
foreach loops nested four levels deep, but it works. But populating the form – that’s not working. I have set the hydrator =
ArraySerializable, I instantiate my ArrayObject and
bind() the form to it,
$form->setData($object) on it, etc, etc, no luck. No errors or anything, just quiet failure to set the form values.
I think this form initialization should work before getting into input filters and validation, so I assume that is not the problem.
So: do I have to make multiple nested Fieldsets in order to populate a form from a hierarchical ArrayObject? Or is there some way that I am overlooking?