diff --git a/src/Cms/Pages.php b/src/Cms/Pages.php index 692d047b93..34e6899662 100644 --- a/src/Cms/Pages.php +++ b/src/Cms/Pages.php @@ -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; diff --git a/tests/Cms/Pages/PagesTest.php b/tests/Cms/Pages/PagesTest.php index 657bcb3ed3..d26d9a0f42 100644 --- a/tests/Cms/Pages/PagesTest.php +++ b/tests/Cms/Pages/PagesTest.php @@ -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([