I came across an interesting issue with the Kirby hooks, which is that it can be called with null values?
The cases I got currently are the page.update:before and page.update:after hook, both of which are called with a null value for both the newPage and the oldPage argument.
So what does the null value mean? And how do I fix this (since I want to use both references in the hook itself).
Ps. I have been changing the template/blueprint between changing the page contentās, if that should make a difference (not sure how I would otherwise force an file-write tbh). I tried with a fresh page, still the same problem
This happens when I try to save a page from the panel. The page already exist, and when I use the āafterā version of the hook. All changes are saved correctly, but it will crash when I try to use either function-parameter because those are null.
App::plugin('my/plugin', [
'hooks' => [
'site.update:after' => function ($newSite, $oldSite) {
},
'page.create:after' => function ($page) {
},
'page.duplicate:after' => function ($new, $original) {
},
// 'page.update:before' => function ($new, $old) { < this one yields the same result
'page.update:after' => function ($new, $old) {
// At this point, both $new and $old are `null` for some reason.
},
'page.delete:after' => function ($status, $page) {
}
],
]);
You have to use the correct named parameter names as in the documentation, for the page.update:after hook that would be$oldPage and $newPage,not $new and $old.