0

With a config form, when saving the fields in the submit, rather than

->set('FIELD NAME', $form_state->getValue('FIELD NAME')

how would a form with #tree = true be handled?

For example: $field[topic1][subtopic_a] $field[topic1][suntopic_b]

2
  • Give us more info, and it will be easier to provide an answer. What is the data? Do you want to store each value separately, or can it be an array etc?
    – Jaypan
    Jun 26 at 1:25
  • So, the form is constructed dynamically from a yaml file. At the time of submitting, the actual fields that need to be saved (as opposed to the details field enclosing them) might look like the example I’ll put above, other than the fact that it can go 5 levels deep. I don’t care how it is stored as long as I can get to the values when the form is built again.
    – JAyenGreen
    Jun 26 at 1:33

1 Answer 1

1

You can store an array to configuration. So you can almost use the code you provided. You could do something like:

->set('FIELD NAME', $form_state->getValue(['field_name']);

Where field_name is the key of the element that has had #tree set to it, containing child elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.