Closed medienbaecker closed 4 years ago
Redirection in a panel hook is not possible (yet) since hooks can only interact via throwing Exceptions.
I'll try putting the redirection in a custom field that will be present on the modules container.
Redirecting in a field doesn't seem trivial either.
For now there should be a blueprint for the modules container with an info field. It's not ideal, but better than displaying the default blueprint.
My guess is you'd like to redirect to the module's grandparent page, the one containing the main content. I'm also assuming that Kirby is always redirecting to the direct parent after deleting a page. So have you tried changing the modules parent from the module container to the actual content page before deletion?
@nilshoerrmann That's a great idea and I didn't think of this at all. Unfortunately—if I did everything right—it doesn't work either.
I added this hook:
'page.delete:before' => function ($page) {
if($page->parent()->intendedTemplate() == "modules") {
$oldPageFolder = basename($page->contentFileDirectory());
$newPageFolder = $page->parent()->parent()->contentFileDirectory() . DIRECTORY_SEPARATOR . $oldPageFolder;
Dir::move($oldPageFolder, $newPageFolder);
}
}
But it still redirects to the modules container page. I think the variables are set before the :before
hook or something like that?
Okay, I'm only guessing, but maybe it's possible to manipulate the $page
object that is passed to the hook. So maybe you could just make the page "think" that it has a different parent without actually moving folders?
I spent hours trying to get this redirection to work—no chance. For now I added a link to the parent page in the modules blueprint. This way you can at least get to the parent page with one click.
Maybe you could ask Bastian, if it's possible at all. Does Kirby allow for custom routes for the panel maybe?
Unfortunately it seems like there's no solution for this.
I think I found a solution. It's quite hacky but it works:
The modules plugin now includes a simple modules_redirect
field.
I pass $this->model()->parent()->panelUrl()
to it and redirect to this url on render
.
You can check it out in the branch feature/modules_redirect.
Hacky – but clever! 👍
When deleting a module you get redirected to the (otherwise invisible) modules container.