Getting file/page references/arrays in a model's `writeContent` as arrays

Hey there,

I’m trying to save parts of my site to a SQLite database, so obviously I read both of the cookbook articles (Using databases | Kirby CMS and Content from a database | Kirby CMS). Unfortunately neither one goes into detail on how to write back more complex content than text/numbers/booleans.

So if I want to write the value of a “reference” field (e.g. a file, an image, a page, etc.) to my database, I obviously have to implement the writeContent function in my model.

writeContent receives a $data parameter. However, the value of all reference fields is not an array of all the referenced UUIDs (which I would have expected), but instead it’s a multiline YAML string.

So, I’m getting something like this:

(
    [invnum] => 701
    [registered] => 2024-05-12
    [manufacturer] => 3D-Druck
    [price] => 16
    [images] => - file://eNIhk6X0G3NN0W0d
- file://1qUsdFpHdgUJK0um
- file://EWuxHTYJGql0LXcE
)

And this is what I would expect/would love to have:

(
    [invnum] => 701
    [registered] => 2024-05-12
    [manufacturer] => 3D-Druck
    [price] => 16
    [images] => ["file://eNIhk6X0G3NN0W0d", "file://1qUsdFpHdgUJK0um", "file://EWuxHTYJGql0LXcE"]
)

Now do I really need to manually split/format this string into an Array myself? Or are there any helpers, flags or other methods I can use, to get an actual Array here?

Is this an intentional design decision to already use YAML values here in the model?

It’s an “intentional” design from when that code part was written and plain text content files where the only storage on our minds. For some time in the future, we likely would want to change this - see code changes in v5 to start introducing storage handlers (still not fully fledged). Eventually we would want those handlers manage how they deal with different data types (strings, arrays…) instead of already converting this earlier in the chain. But for now, there is no simple flag, option etc. to retrieve this, sorry.

1 Like

Thanks for the answer. Looking forward to the upcoming changes regarding storag abstractions. Guess I’ll have to do some string chopping until then.