Skip to content

Commit

Permalink
Include drafts in finding pages key recursively
Browse files Browse the repository at this point in the history
Fixes #6339
  • Loading branch information
distantnative committed Mar 23, 2024
1 parent 202387f commit 94ea2a4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Cms/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected function findByKeyRecursive(
$query = $startAt;

foreach ($path as $key) {
$collection = $item?->children() ?? $this;
$collection = $item?->childrenAndDrafts() ?? $this;
$query = ltrim($query . '/' . $key, '/');
$item = $collection->get($query) ?? null;

Expand Down
44 changes: 44 additions & 0 deletions tests/Cms/Pages/PagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,50 @@ public function testFindChildrenWithSwappedSlugsTranslated()
$this->assertIsPage('zzz/yyy', $pages->find('zzz/yyy'));
}

public function testFindChildrenDrafts()
{
$app = new App([
'roots' => [
'index' => '/dev/null'
],
'site' => [
'children' => [
[
'slug' => 'grand',
'children' => [
[
'slug' => 'mother',
'children' => [
[
'slug' => 'child',
]
]
]
],
'drafts' => [
[
'slug' => 'father',
'children' => [
[
'slug' => 'child',
]
]
]
]
]
]
]
]);

$site = $app->site();

$this->assertIsPage('grand', $site->children()->find('grand'));
$this->assertIsPage('grand/mother', $site->children()->find('grand/mother'));
$this->assertIsPage('grand/father', $site->children()->find('grand/father'));
$this->assertIsPage('grand/mother/child', $site->children()->find('grand/mother/child'));
$this->assertIsPage('grand/father/child', $site->children()->find('grand/father/child'));
}

public function testFindMultiple()
{
$pages = Pages::factory([
Expand Down

0 comments on commit 94ea2a4

Please sign in to comment.