Hello everybody,
I am trying to redirect to a parent page called “blog” if the user changes the date year to another one as the date year before.
This is how my hook looks actually
use Kirby\Panel\Panel;
...
'options' => [
'fieldName' => [
'publishDateFieldName' => 'publish_date'
]
],
'hooks' => [
'page.update:after' => function ($newPage, $oldPage) {
if ($newPage->intendedTemplate() == 'blog-article') {
$dateField = option('vendor.plugin.fieldName.publishDateFieldName');
$oldPagePublishYear = $oldPage->$dateField()->toDate('Y');
$newPagePublishYear = $newPage->$dateField()->toDate('Y');
if ($oldPagePublishYear !== $newPagePublishYear) {
Panel::go(Panel::url('pages/blog'))
}
}
}
]
The date comparison works as expected, the renaming of the option field works as expected but when it comes to the Panel::go() method I get the error:
The form could not be saved
Exception: Kirby\Panel\Redirect
http://steilaufwaertss-macbook-pro.local:8888/kirby/ensun/panel/pages/blog
Is there a chance to get the redirect to work? Do I have to interact via JavaScript then? Or does anyone else have an idea? I tried an own Hook that gets triggered, when the page.update:after hook fires. But that didn’t do the trick. The error is still the same.
Maybe someone has a workaround or something?
Kindest regards
Mo