Redirect within panel.page.create

I have a page that represents a city. In a panel.page.create hook, I am doing a geocoding lookup in Google Maps and then renaming the page according to what Google tells me it should be, in order to avoid duplicate city pages with different pronunciations.

Sometimes the page I am ‘moving’ to already exists. Then I want to delete the current page and redirect the user to the user that was already there.

I have gotten as far as being able to delete the current page if there is one with the same slug already there. But I can’t find a way to redirect the panel to it…

This should work:

$uri = $page->uri(); // whatever page uri you need here
$this->panel()->redirect('pages' . DS . $uri . DS . 'edit');
2 Likes

wow - I wasn’t expecting it to be possible - thanks!

Another option is:

$blog = panel()->page('blog'); // must be an instance of Kirby\Panel\Models\Page
$this->panel()->redirect($blog, 'edit');
2 Likes

I need to reopen this topic. In the meanwhile the $this->panel()->redirect() methode is gone and

$uri = $newPage->uri();
Panel::go('pages' . DS . $uri . DS . 'edit');

only shows a dialog with the path inside.

Is there a proper way in Kirby v4 for this?