I am currently developing a custom panel field that has several inputs for every day of the week to give the user the opporturnity to enter opening or visiting hours.
The form itself looks good so far in the panel, but the data is not stored in the content folder. I implemented the text input fields with array name notation (eg. hours[Sun][from], hours[Sun][to], hours[Mon][from] etc). When I debug the app until the call to $site->update(), everything looks fine to me.
Is Kirby capable of storing this array data? If yes, do I need to do something special?
First, I do not want to use the core structure field for several reasons
Where should the encoding be done? Is it done in the field class or in a custom field controller?
The Panel calls the result method of your field. It should return a string with the value you want to store. So in your case, you would get the data from the request and convert it to YAML.
Another thing: You probably shouldn’t hard-code the name of the input (“hours”), otherwise you can’t use multiple fields of the same type. The recommended way is to use $this->name() instead.
Thanks a lot @lukasbestle. That explained a lot. I missed the line with the call to $field->result(). I will work on from here myself and see how much further I get
Whatever other field you’ve extended should implement the method already, so calling parent::result() ought to grab your data out of the POST request, which in our cases will be the multi-dimensional PHP object.
The Toolkit provides the YAML encoding functionality you need.
Also! Be sure to implement the value method to make sure your data is decoded when loaded into the panel.