I have a site that uses a database. Everything works but the draft status is saved in the database as ‘null’ and is then not visible in the panel. I used the guide: Content from a database | Kirby CMS
This is the model:
$entries[] = [
'slug' => $entry->slug(),
'num' => $entry->status() === 'listed' ? 0 : null,
'template' => 'portfolioitem',
'model' => 'portfolioitem',
'content' => [
'title' => $entry->title(),
'uuid' => $entry->id(),
'status' => is_null($entry->status()) ? 'draft' : $entry->status(),
]
];
protected function changeStatusToDraft(): static
{
$data['status'] = 'null';
if ($comment = Db::first('portfolio', '*', ['slug' => $this->slug()])) {
Db::update('portfolio', $data, ['slug' => $this->slug()]);
}
return $this;
}
protected function changeStatusToListed(int|null $position = null): static
{
// create a sorting number for the page
$num = $this->createNum($position);
// don't sort if not necessary
if ($this->status() === 'listed' && $num === $this->num()) {
return $this;
}
$data['status'] = 'listed';
if ($comment = Db::first('portfolio', '*', ['slug' => $this->slug()])) {
Db::update('portfolio', $data, ['slug' => $this->slug()]);
}
if ($this->blueprint()->num() === 'portfolioitem') {
$this->resortSiblingsAfterListing($num);
}
return $this;
}
protected function changeStatusToUnlisted(): static
{
if ($this->status() === 'unlisted') {
return $this;
}
$data['status'] = 'unlisted';
if ($comment = Db::first('portfolio', '*', ['slug' => $this->slug()])) {
Db::update('portfolio', $data, ['slug' => $this->slug()]);
}
$this->resortSiblingsAfterUnlisting();
return $this;
}
public function isDraft(): bool
{
return in_array($this->content()->status(), ['listed', 'unlisted']) === false;
}