Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page.changeStatus:before hook position param issue on drafts and unlisted #1982

Closed
afbora opened this issue Aug 7, 2019 · 1 comment

Comments

@afbora
Copy link
Contributor

commented Aug 7, 2019

https://getkirby.com/docs/reference/plugins/hooks/page-changestatus-before

return [
    'hooks' => [
        'page.changeStatus:before' => function ($page, $status, $position) {
            // your code goes here
        }
    ]
]

If you try to use page.changeStatus:before hook like in the document, you will get following error on changed page status to draft or unlisted

Too few arguments to function Kirby\Cms\App::{closure}(), 2 passed and exactly 3 expected

Because draft and unlisted pages have no position and doesnt send this param as you can see following methods:

$page = $this->commit('changeStatus', [$this, 'draft'], function ($page) {

$page = $this->commit('changeStatus', [$this, 'unlisted'], function ($page) {

Kirby Version
3.2.3


We can solve this issue with two ways:

1. Update the document with position variable assigned null param like that:

return [
    'hooks' => [
        'page.changeStatus:before' => function ($page, $status, $position = null) {
            // your code goes here
        }
    ]
]

This seems sufficient, but if you want to have a standard in parameters, check out the second option.

2. Send position param as null while trigger the event:

$page = $this->commit('changeStatus', [$this, 'draft', null], function ($page) {
    return $page->unpublish();
});

$page = $this->commit('changeStatus', [$this, 'unlisted', null], function ($page) {
    return $page->publish()->changeNum(null);
});
@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.