Programmaticly update page with object field

I’m trying to update a page programmaticly using page()->update():

something like this:

page( $page->id() )->update([
    'title' => "test",

with works very well. But I can’t figure out how to update an object field:

I can’t seem to find any example so I tried a few things like wrapping the object fields in an array but no luck. Anyone out there who can point me in the right direction?


Could you please post what array you tried?

Yes. I thought simple and plain like this:

  'myObject' => [
    'title' => "test",

That should work and works in my little test. What do you get as result? Is the object field defined in the blueprint of the page you are trying to update? And does the subfield title exist?

Yes, i did define them in the bleuprint and it seems to work there:

            type: object
                type: text

shows me this in the content file:

Rheader: rtitle: ok

when i then try to change it:

  page( $page->id() )->update([
    'rheader'  => [
      'rtitle' => "test",

nothing seems to change. if i change other (not object fields) it works great.

one thing that might be problematic is that i call the update function in a “file.create:after” hook because i would like to get specific contents from that file and store it in the object. so i do need to reload the page manually for the fields to change. could that be the problem?

I don’t know. Yes, you need to reload for the changes to reflect in the Panel, but the field content in the page’s content file should nevertheless change.

Let me try from a hook.

On a side note: Why don’t you just use $page->update() instead of trying to fetch the page you already have with page($page->id())?

Ok, I tried from a hook, and the content file is updated, but of course the change does only reflect in the Panel after reloading the page.