Disable Draft Status

Lets see if I stumbled on a bug or if this is the intended behaviour.
I’m setting up the blueprint for the homepage of a site and I’m trying to configure the status

If I use this

status:
    draft    : Draft
    unlisted : Unlisted
    listed   : Published

Everything works as expected

But if I try to disable the draft and only allow for listed/unlisted like this

status:
    unlisted : Unlisted
    listed   : Published

Then the draft is back with also the extra help text

So the question is: Is there a way to allow users to switch status between listed unlisted without allowing a page to be set as draft?

1 Like

You can’t disable the draft state. All pages are always created as drafts first. Are you using a hook to set a listed or unlisted state on page creation?

No I was trying to find a way to prevent users to set the homepage as draft

Why don’t you just set changeStatusto false? Doesn’t really make sense to switch between published and listed for the home page.

On my site visible pages are displayed in a list in the footer.
So if you want a page to be displayed there you simply change the status to visible.

Worked flawlessly on K2.

Now in K3 i have this draft variable added to the mix.

Also, doesn’t make much sense to be able to set the homepage of the site as draft :smile:

It doesn’t even work to set the home page as a draft. So yes, the option shouldn’t even be visible for the homepage. Could you file an issue, please?

For all other pages, you wouldn’t be able to create pages if there was no draft state.

Could you file an issue, please?

Absolutely. Doing it now.

As for this:

For all other pages, you wouldn’t be able to create pages if there was no draft state.

This is another issue and I think there could be a solution (for example allow the possibility of creating pages with the desired status as default) but it’s not that important right now :wink:

…or, if we had the ability to programatically override blueprint options, you could use a page.create:after hook to change the status of the page after creating it, even if in its blueprint you had set its changeStatus: false.

Although useful this wouldn’t really solve my problem because my main issue is with pages that are already there such as the homepage.

You could just hide this option with css

Unless I’ve overlooked something, I don’t think you can do that just for that single page, you’d hide the draft option from every single page.

You are right. I keep forgetting that I am using this plugin: Kirby 3: Panel View Extended

Yep, that’s a different story. However, it would just be a workaround while the issue that the draft option exists when you can’t make the home page a draft page, persists.

This is fixed on RC 3.0.1 and will be in the next release.

@texnixe Is there a way to set pages to prevent editors from turning published pages into drafts again?

We’re using the following hook to publish a page automatically as soon as it’s created:

'page.create:after' => function ($event, $page) {
    $pagesToUnlist = [
        'pages/news-category',
        'pages/news-category-index',
    ];
    if (in_array($page->blueprint()->name(), $pagesToUnlist)) {
        $page->changeStatus('unlisted');
    }
},

This works fine, any new page is set to unlisted as soon as it’s created. But editors still have the option to turn the page back into a draft, which we don’t want to allow in this case.

We tried to set changeStatus: false in the blueprint. But this disables not only the option in the panel, but also the API apparently, so with this we can’t create any new pages since the hook will cause an error.

Is there a simple way to set pages to be published automatically (skipping the draft stage) and not allow editors to change the status?

You can set this to false only for the editor rule, should still allow you to change the status as the impersonated kirby user or the admin.

changeStatus:
  editor: false
1 Like

@texnixe Thanks for the suggestion! Using roles to limit access is a solid option. Though for small sites with only few editors, we won’t create any roles or permission checks, so it would still be nice if it was possible to achieve this behaviour for everyone.

You should be able to programatically create a page in other status than draft with Page::create.

It takes a bit of work - you need (?) to add more stuff, but it works:

$page = Page::create([
  'kirby' => kirby(),
  'site' => site(),
  'parent' => $parent,
  'isDraft' => false,
  'num' => null

  /* … and slug, template, model and content */
])->save();
1 Like