Page.update:after not called from API endpoint

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?

Could you check if this hook actually works when you update through the Panel?

Thanks, @pixelijn
This lead me in the right direction: page.update:after has $newPage as an argument, but not $page… The panel threw the respective error. Sorry, my fault.
However, now the create hook is broken. I will investigate this now, but your hint was surely helpful and I guess the create hook issue has a different root cause.

I wonder if there is in issue with the wildcard hooks in general.

I don’t think that the wildcard hooks have a general issue. They are just to be used with care with respect to argument names.
My create hook issue is now also solved: After creating the new page it was saved as a draft (even though ‘isDraft’ was set to false; this might actually be an issue) and I checked for the parents children in the hook callback. So the new page wasn’t returned. So I will now either check for childrenAndDrafts or use the changeStatus hook as I change the page status immediately after creation, anyway.
Thanks again for pointing in the right direction, @pixelijn.

Regarding the isDraft issue: Am I misunderstaning this parameter or should this really create a non-draft page (see my initial post). I have a feeling, my conception of this parameter is wrong.

Setting the isDraft property doesn’t have any effect when creating a page, i.e. the page is still created as draft. On a side note, setting it to a string 'false' instead of a boolean false is not correct, anyway.

OK, thanks @texnixe ! Issue solved.