How can I *update* a block's field values programmatically?

I found this threat looking for the same thing. My use case is that I built a very simple form editor using blocks where I want to store the input data in the block.

In this case the great how to update blocks programmatically quicktip didn’t help me but I found this cookbook section about updating content within blocks. It shows how to convert individual blocks to arrays, manipulate the content and convert them back to blocks.

Edit: Didn’t work. Fields turned into default text fields. Found this hint by @texnixe, that you have to covernt the blocks object into an array when storing it:

$page->update([
    'text' => $blocks→toArray()
]);
2 Likes