Binding a Zend\Form\Form to a hierarchical ArrayObject without using fieldsets

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.,

name="some_event[condition_x][condition_y][do_something]"

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?

Thanks.

OK I think I might have a (if not the) solution: compromise. For each top-level key in my configuration, one fieldset. Within each of those, no more nesting: flatten out the names using dot notation. If I’m right I will be so excited, I’ll be sure to come back and tell you more about it. :grinning:

UPDATE: Correct me if I’m wrong but I think the takeaway is: you can’t do what I was trying to do (with nested arrays, object hydration and form-binding without nesting fieldsets), so don’t try.