Panel.page.move - Get old uri?

When I use the hooks create, update and delete I can get the page uri or page id from the $page object.

When I rename a slug (move hook) I only get the new uri / id. It’s expected behaviour, but how can I get the old uri / id?

Any outside the box thinking here would be fine for me

kirby()->hook('panel.page.move', function( $page ) {
  //$page->id();
});

Update

This might be one solution. There are two (maybe minor) problems I see with it:

  • It takes up space in every text file on the whole site (the way I need to use it).
  • If it’s activated when the site already has pages, the value would not exist until the page is updated. That might not happend before the user decides to rename the slug.

Alternatives are welcome, even comments about that the answer above is the only way to go, if that is so.

I was just going to suggest that …

Edit:

True, but not a lot.

That’s definitely the bigger problem. You could create the field on page.create, but if the page was created outside the panel, you have no luck and would have to create these fields manually.

Currently, no better idea to offer.

Even simpler: The move hook already passes the “old” object before the move:

kirby()->hook('panel.page.move', function($new, $old) {
  ...
});

It is just missing from the docs.

4 Likes

Let’s add that to the docs, then …

1 Like

My goodness Lukas! That’s awesome! Your head is much more complete than the docs! :smiley:

Thanks @texnixe for your answers as well.

1 Like

Does this apply only to the move hook, or update as well?

From looking at the source code, this seems to apply only to the move hook.

/panel/app/src/panel/models/page.php