Hi everyone,
I am having a hard time debugging a strange issue. I am creating/updating/deleting pages via Kirby API endpoints. Upon each action (create/update/delete) I want to call a custom site method (same for each action). So I am using a hook. The hooks for create and delete are triggered as expected, but the hook for update is not triggered.
I am using this hook:
'page.*:after' => function ($event, $page) {
if (!in_array($event->action(), ['create', 'update', 'delete'])) {
return;
}
if ($page->intendedTemplate() == 'pagetype') {
site()->doSomething();
}
}
The API endpoints are something like
'pattern' => 'createPage',
'method' => 'post',
'action' => function () {
site()->find('parentPage')->createChild([
'template' => 'temp',
'slug' => 'myslug',
'isDraft' => 'false',
'content' => [
// omitted here
...
],
])->changeStatus('listed');
}
'pattern' => 'updatePage',
'method' => 'post',
'action' => function () {
...
$page->update($newContent);
...
// following is used for debugging
site()->doSomething();
}
The funny thing is: The page is actually updated, but the page.update:after
hook is not called (site()->doSomething()
is not executed), but when I call site()->doSomething()
from within the API endpoint (see above), the function is executed.
Can anyone explain, why the page.update:after
hook is not triggered in my example?