Reference newly duplicated page

I have a hook that duplicates a page:

$newPage->duplicate('-inv'); 

How can I access the new page, to change its status, move it etc… ?

You need to store the return value in a variable:

$duplicate = $newPage->duplicate('-inv'); 
// then work with $duplicate

thanks!

This works great:

       $duplicate =  $newPage->duplicate('-inv');
       $duplicate->changeStatus('unlisted');

I thought I could do this to then go to the new page:

      $uri = $duplicate->uri();
       site()->panelUrl($uri);

Is there another method?

Currently, there is no way to redirect from a hook to a different location.

ah, ok - I have opened a feature request: https://github.com/getkirby/ideas/issues/373

1 Like