Skip to content

Commit 555f22f

Browse files
committed
Fix draft previews for Kirby 5
1 parent d362812 commit 555f22f

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use Kirby\Cms\App as Kirby;
44
use Kirby\Cms\Pages;
5-
use Kirby\Template\Template;
65
use Kirby\Toolkit\Str;
76

87
include __DIR__ . '/lib/models.php';
@@ -36,7 +35,9 @@
3635
'modules' => function () {
3736
$modules = new ModulesCollection;
3837
if ($modulesContainer = $this->find('modules')) {
39-
foreach ($modulesContainer->children()->listed() as $module) {
38+
foreach ($modulesContainer->childrenAndDrafts() as $module) {
39+
if ($module->isUnlisted()) continue;
40+
if ($module->isDraft() && $module->renderVersionFromRequest() === null) continue;
4041
$modules->append($module);
4142
}
4243
}

lib/models.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
use Kirby\Cms\Page;
44
use Kirby\Cms\Pages;
5+
use Kirby\Cms\Site;
56
use Kirby\Content\VersionId;
67
use Kirby\Template\Template;
78

89
class ModulePage extends Page
910
{
10-
public function parentUrl(): string
11-
{
12-
return $this->parents()->count() ? $this->parents()->first()->url() : $this->site()->url();
13-
}
1411
public function render(
1512
array $data = [],
1613
$contentType = 'html',
1714
VersionId|string|null $versionId = null
1815
): string {
19-
go($this->parent()->url() . '#' . $this->slug());
16+
17+
$parentUrl = $this->page()->url();
18+
if ($token = get('_token')) {
19+
$parentUrl .= '?_token=' . $token;
20+
}
21+
22+
go($parentUrl . '#' . $this->slug());
2023
}
2124
public function renderModule(array $params = [])
2225
{
@@ -29,11 +32,19 @@ public function renderModule(array $params = [])
2932
...$params
3033
]));
3134
}
32-
public function moduleName()
35+
public function page(): Page|Site
36+
{
37+
return $this->parent()->parent() ?? $this->site();
38+
}
39+
public function parentUrl(): string
40+
{
41+
return $this->page()->url();
42+
}
43+
public function moduleName(): string
3344
{
3445
return $this->blueprint()->title();
3546
}
36-
public function moduleId()
47+
public function moduleId(): string
3748
{
3849
return str_replace('.', '--', $this->intendedTemplate());
3950
}
@@ -42,7 +53,7 @@ public function parents(): Pages
4253
$parents = parent::parents();
4354
return $parents->filter('slug', '!=', 'modules');
4455
}
45-
public function metaDefaults()
56+
public function metaDefaults(): array
4657
{
4758
return ['robotsIndex' => false];
4859
}

0 commit comments

Comments
 (0)