$oldPage in hooks doesn't return previous version of the page

Add following in a hook:

kirby()->hook('panel.page.*', function($page, $oldPage = null) {

When you update the title value (via the panel) you should see the new value first, followed by the previous value thereafter in the error log.

This is not the case on my install. What am i doing wrong?

This is a known issue: https://github.com/getkirby/panel/issues/1025

Ouch. Did you find a way to work around this @thguenther?

As I experience it, $oldPage never seems to work in the hooks. A pretty nasty bug if you ask me?

$oldPage used to work, though, as far as I remember. Need to look into this. Otherwise, we have to create a new issue on GitHub.

@texnixe this seemed to work with a new starterkit, so I investigated this a bit further and come to the conclusion that this whole $oldPage functionality breaks the moment you add a field of the type “image” to the blueprint.

The “select field” (upon the image field extends) works perfectly, so the problem has to be inside the image field somewhere. Could you help me find a way around this problem now?


@bvdputte Thanks for investigating this further. I just didn’t get round to looking into this, currently preparing to move flat this Saturday, so very little time, unfortunately. I’ll try to look into this as soon as possible. In the meantime, could you please create an issue on GitHub, as this seems to be a bug that is different from the one @thguenther linked to.

Thanks, have fun moving into your new place!
I have added an issue to the panel on GitHub (I hope that this is the correct place).

If anyone can help me working around this in the meantime, that would be awesome! — thx

Hm, I tested this with image field and panel.page.update hook and couldn’t reproduce the issue.

How about using this:

kirby()->hook('panel.page.*', function($page, $oldPage = null) {

Yes, I ran your code from the first post as well without any issues. The hook is triggered and if I change the title, it logs two different titles.

Try again in a multilingual setup please?

I have this in my config:

// Languages
c::set('languages', array(
    'code'    => 'en',
    'name'    => 'English',
    'default' => true,
    'locale'  => 'en_US',
    'url'     => '/en',
    'code'    => 'nl',
    'name'    => 'Nederlands',
    'locale'  => 'nl_BE',
    'url'     => '/nl',
    'code'    => 'fr',
    'name'    => 'Français',
    'locale'  => 'fr_BE',
    'url'     => '/fr',
    'code'    => 'de',
    'name'    => 'Deutsch',
    'locale'  => 'de_de',
    'url'     => '/de',

In a multi-lang starter kit, I get this result: With an image selected in the image field, the hook is triggered but new and old title stay the same. With no image selected, the hook works as expected-

Yes, I can confirm this behaviour.

So, basically, when you

  • have a multilingual setup
  • use the image field
  • have an image selected in that image field

$oldPage in hooks is broken.

Yes, exactly like this.

@lukasbestle, any chance you can take a look at this and help me out? Thanks!

1 Like

I have seen your GitHub issue and will be taking a look at it for the next release. It needs more investigation. :slight_smile:

1 Like

Thx @lukasbestle, I can’t wait :see_no_evil: