Skip to content

Page::create ignores isDraft #5042

@SeriousKen

Description

@SeriousKen

Description

The code I have written to populate a blog with a mix of drafts and published articles prefixed with the value from the date field for sorting fails, all pages are drafts. The isDraft prop is documented here https://getkirby.com/docs/reference/objects/cms/page/create.

To reproduce

  1. composer create-project getkirby/plainkit
  2. Change dir into the project
  3. composer require fakerphp/faker
  4. Create a file seed-blog.php in the root of the project with the following:
<?php

use Kirby\Cms\Page;

require 'kirby/bootstrap.php';

$app = new Kirby();
$app->impersonate('kirby');

$blog = $app->site()->find('blog');

$faker = Faker\Factory::create();
$faker->seed(12345);

for ($i = 0; $i < 100; $i++) {
    $date = $faker->dateTimeThisDecade();
    $page = Page::create([
        'parent'   => $blog,
        'slug'     => $slug = join('-', $faker->words(5)),
        'isDraft'  => $faker->boolean(25),
        'template' => 'article',
        'content'  => [
            'title' => $faker->sentence(),
            'date'  => $date->format('Y-m-d H:i:s'),
            'body'  => $faker->paragraphs(5, true),
        ],
    ]);
}
  1. Create content/blog folder
  2. Create site/blueprints/pages/article.yml with the following:
num: '{{ page.date.toDate("Ymd") }}'

fields:
  date:
    type: date
  body:
    type: textarea
  1. php seed-blog.php

Kirby Version

3.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions