Using $page→update($content, $language) with partial data for Structure Fields

I’m trying to programmatically translate content of a page. I’ve set some fields to “translate: false” so that they cannot be changed in the panel.

I’m now trying to update Structure Fields of a page with a new data array. But this data array does not have all the fields. Only some.

Problem: When using $page→update($content, $language) and passing an incomplete $content array, e.g. where some nested fields (Structure) are missing, those excluded fields become empty in the translation.

Is this intended? Is the $page→update() not patching content recursively, but rather replaces entries of a structure?

Yes, it replaces the data, that’s why you have to first get the data from the field, replace where necessary and then update.

Okay good to know. I guess I’ll try to fetch the original content and merge it with the translation. :slight_smile:

That said, is there a way to get the content as a nested array?


Gives me a YAML string for Structure Fields :confused:

I think you better deal with the structure field separately, because you have to turn that into an array using the yaml() method.